I am new to aws lambda and api gateway and I am trying to pass a json string to the lambda function.
However, the lambda is not being called with the string.
This is the lambda. It gets an object as input and returns a string representation of the class and the value of the object.
public class TestMapping implements RequestHandler<Object, String> {
@Override
public String handleRequest(Object input, Context context) {
return "inputClass = " + input.getClass() + ", input = " + String.valueOf(input);
}
}
The mapping template for the api gateway is
#set($allParams = $input.params().querystring)
{
"resourcePath" : "$context.resourcePath",
"httpMethod" : "$context.httpMethod",
"header": "$input.params().header",
"path": "$input.params().path",
"inputJson": "$input.json()",
"queryParameters" : [
#foreach($type in $allParams.keySet())
{"name": "$type", "value": "$allParams.get($type)"}#if($foreach.hasNext),
#end
#end
]
}
The log in the api gateway test says:
Endpoint request body after transformations: {
"resourcePath" : "/testmapping",
"httpMethod" : "GET",
"header": "{}",
"path": "{}",
"inputJson": "",
"queryParameters" : [
{"name": "month", "value": "6"},
{"name": "employeeId", "value": "1"}
]
}
I expected the json string to be passed to the lambda (as a string object), but instead of this the TestMapping Lambda returns
"inputClass = class java.util.LinkedHashMap, input = {resourcePath=/testmapping, httpMethod=GET, header={}, path={}, inputJson=, queryParameters=[{name=month, value=6}, {name=employeeId, value=1}]}"
As you can see, a LinkedHashMap is passed to the lambda.
What can I do, to get a string object passed to the lambda with the json string as value?