Reputation: 3459
Here is my lambda function:
@Override
public List<JobData> handleRequest(Map<String,String> searchFilters, Context context) {
List<JobData> jobs = new ArrayList<>();
if(searchFilters.get("job_title") != null){
// populate jobs list using a method.
}else{
// populate jobs list using another method.
}
return jobs;
}
I used the below test event for testing the lambda:
And the lambda function is working as expected for the above mentioned test input.
Then, I created an API gateway with a POST request triggering the above mentioned lambda function:
Then, I used the REST API gateway to send a POST request with the below body content with a header Content-Type : application/json
.
request body:
{
"job_title": "software engineer"
}
But it is navigating to the else
block in the lambda code (indicating that API gateway is not properly intercepting the POST request parameters) which is not expected.
I tried permutations and combinations with the API gateway configurations in AWS. But none of them worked. I get a feel that my lambda function might need to be changed to make it work with API gateway. What can I try next?
Upvotes: 3
Views: 4546
Reputation: 201048
By default, the POST request is not sent directly to the Lambda as the event
object. The event
object will have much more in it than what you have in your test case, and the actual POST data will be down in one of the event object's properties. If you are using Lambda proxy integration in API Gateway, then the event will look like this.
You have two options:
Create a custom mapping template in API Gateway to convert the event sent to Lambda into what you are expecting.
Modify your Lambda code to handle the format that is currently being sent. I suggest using this library.
Upvotes: 5