I was just having a really basic problem using aws-lambda, API Gateway and the serverless framework. I just wanted to hand over the body of a post request as a Java POJO.
Okay, so here's the setup:
POJO:
public class Person {
private String lastName;
private string firstName;
... Setters and Getters omitted
}
Handler:
public class PersonHandler implements RequestHandler<Person, ApiGatewayResponse> {
@Override
public ApiGatewayResponse handleRequest(lastNamePerson person, Context context) {
//... do something
}
}
And the payload in the post's request body would be
{
"lastName" : "John",
"firstName" : "Doe"
}
And, last but not least the serverless.yml
{
...
functions:person
handler:com.serverless.handler
event:
-http:
path:person
method:post
...
}
Well, looks pretty straight forward, doesn't it?
Unfortunately, it's not that simple. The Person POJO will always be empty when calling the function. How can we give the body as a POJO in AWS API Gateway & Lambda?