Closed JakimLi closed 6 years ago
I faced the same problem and there is a definately a bug here. The lambda function gets the content of the POST as JSON, not only the body. Below is what is passed to my test Lambda function. I would have assumed that just {'foo': 'bar'}
would have been passed to the Lambda function.
/usr/bin/java
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=5005
-XX:MaxHeapSize=1336935k
-XX:MaxMetaspaceSize=157286k
-XX:ReservedCodeCacheSize=78643k
-XX:+UseSerialGC
-XX:-TieredCompilation
-jar /var/runtime/lib/LambdaJavaRTEntry-1.0.jar
com.some.EchoHandler
{"httpMethod":"POST","body":"{\"foo\":\"bar\"}","resource":"/echo","requestContext":{"resourcePath":"/echo","httpMethod":"POST","stage":"prod","identity":{"sourceIp":"127.0.0.1:58482"}},"queryStringParameters":{},"headers":{"Accept":"*/*","Content-Length":"55","Content-Type":"application/json","User-Agent":"curl/7.55.1"},"pathParameters":null,"stageVariables":null,"path":"/echo"}
SAM CLI doesn't do anything special to handle the JSON -> POJO conversion. It is done within the docker container which is a part of github.com/lambci/docker-lambda project
I have a lambda function:
Then when I am testing the lambda using sam local, and send a request:
I am expecting the json converted to
NewNoteRequest
automatically, but it didn't. here is the log:my sam local template:
The POJO:
Also the dependencies are:
I cannot figure out which part is wrong, AWS document says it can do the mapping directly. Please help.