Reputation: 592
I want to combine request body and querystring parameters before sending it to lambda. Let's say I have an entity in Lambda as below :
Class Person {
private String firstName;
private String lastName;
private String language;
}
And the json which sent to api gateway is{"firstName":"Foo","lastName":"Bar"}
As you see "language" field is missing in request body. I want to get this language field from querystring and add to json.
How can I achieve tihs ?
Is there a way to do in integration request section ? For example :
$input.json(x).append("language":"$input.params('name')")
I could not find any valuable information. Thanks in advance.
Upvotes: 4
Views: 5186
Reputation: 8571
You can use body mapping template in the integration request section and get request body and query strings. Construct a new JSON at body mapping template, which will have data from request body and query string. As we are adding body mapping template your business logic will get the JSON we have constructed at body mapping template.
Inside body mapping template to get query string please do ,
$input.params('querystringkey')
For example inside body mapping template,
#set($inputRoot = $input.path('$'))
{
"firstName" : "$input.path('$.firstName')",
"lastName" : "$input.path('$.lastName')"
"language" : "$input.params('$.language')"
}
Please read https://aws.amazon.com/blogs/compute/tag/mapping-templates/ for more details on body mapping template
Upvotes: 2