0
I need to receive a JSON in my API GATEWAY and pass to my LAMBDA ( GOLANG ) a STRING, The Structure Apigatewayproxyrequest the body is String type, when I try to call the lambda passing the json the same break, i need to create a model that converts the received JSON into the STRING gateway before going pro lambda.
Example of how it is today :
##set($allParams = $input.params())
{
## Repassando o json para o lambda
"body":"$util.escapeJavaScript($input.body)",
##"body":"$util.escapeJavaScript($input.body).replaceAll('\"','\\\"')",
## Populando o Headers
"headers": {
## Pegando todos os parametros do header e setando
#foreach($param in $input.params().header.keySet())
"$param": "$util.escapeJavaScript($input.params().header.get($param))"
#if($foreach.hasNext),#end
#end
}
}
Where BODY is of type STRING. When I pass something like :
"body":{"email":"[email protected]","senha":"1234"}
I get error , but if I pass :
"body":"{\"email\":\"[email protected]\",\"senha\":\"1234\"}"
Works normally, already removed the util.escape and nothing I need a model to solve this, taking the JSON and converting to the string type that works , so when I get to the lambda I parse.
Struct lambda
type APIGatewayProxyRequest struct {
Resource string `json:"resource"` // The resource path defined in API Gateway
Path string `json:"path"` // The url path for the caller
HTTPMethod string `json:"httpMethod"`
Headers map[string]string `json:"headers"`
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
PathParameters map[string]string `json:"pathParameters"`
StageVariables map[string]string `json:"stageVariables"`
RequestContext APIGatewayProxyRequestContext `json:"requestContext"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"`
}
good morning, you could insert error?
– Caio Augusto Papai
What if you parse json for string within the gateway api’s capacity? In the resource configuration there is the option to use "Content Handling" to force the conversion to text. This combined with the Mapping Templates feature can convert json to a template that is easy to fulfill the application’s contract. Just a hint focusing more on the aws gateway api than modifying the application itself.
– pedrualves