Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aws Api Gateway Integration Request How to append a property to request body?

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.

like image 262
Mesut Dogan Avatar asked Oct 18 '25 14:10

Mesut Dogan


1 Answers

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

like image 82
Vijayanath Viswanathan Avatar answered Oct 20 '25 05:10

Vijayanath Viswanathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!