Invalid API Gateway Response Keys: {'base64Encoded'} in {'statusCode': 200, 'headers': {'Content-Type': 'text/plain'}, 'body': 'Hello World', 'base64Encoded': False}
See original GitHub issueDescription
We are using aws-serverless-java-container-core to set up our API Gateway proxy lambdas. Each lambda returns an AwsProxyResponse. When run in AWS these lambdas work fine through the configured API Gateways; however, when testing locally with the aws-sam-cli (sam local start-api) we are only able to receive 502 Bad Gateway responses from the local gateway.
It appears that release 0.16.0 of aws-sam-cli added validation to the parameters returned from lambdas (https://github.com/awslabs/aws-sam-cli/pull/1154). When we check the logs for our local lambdas we find that the property for base64encoding is not respecting the declared JsonProperty annotation and is being serialized with a value different that the one that is expected. The serialized value is consistent between the local and AWS environments.
This is a similar issue to the one described in issue 830, but it is unrelated. We are not using the multiValueHeaders field in any of our lambda responses, and the attached error log does not contain this field.
The issue we are facing is that the “isBase64Encoded” field of the AwsProxyResponse object is being serialized with a name of “base64Encoded” rather than the expected name of “isBase64Encoded”. This is resulting in all requests to the local gateway returning 502 regardless of the actual status of the lambda. We are using the AwsProxyResponse object provided by aws-serverless-java-container-core defined here: https://github.com/awslabs/aws-serverless-java-container/blob/master/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/model/AwsProxyResponse.java
Downgrading the aws-sam-cli to version 0.15.0 does prevent the issue from occurring as there is no validation logic present in that version
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
aws-sam-cli version: 0.16.1 aws-serverless-java-container-core version: 1.3
Add --debug flag to command you are running
Error Log: 2019-05-22 14:56:37 Invalid API Gateway Response Keys: {‘base64Encoded’} in {‘statusCode’: 200, ‘headers’: {‘Content-Type’: ‘text/plain’}, ‘body’: ‘Hello World’, ‘base64Encoded’: False} 2019-05-22 14:56:37 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received: {“statusCode”:200,“headers”:{“Content-Type”:“text/plain”},“body”:“Hello World”,“base64Encoded”:false} 2019-05-22 14:56:37 127.0.0.1 - - [22/May/2019 14:56:37] “GET /echoStatusCode/200 HTTP/1.1” 502 -
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (4 by maintainers)
It seems like this issue was fixed on aws-serverless-java-container-core side in 1.3.2, but I am still getting the same error. Please, take a look at this related issue
@jfuss
Looking at the object returned by the serverless java container (
AwsProxyResponse
), the properties are correct.So I think upstream is not responsible for this.
In my comments above I serialized this object with Jackson, and as you can see, the serialization also results in
isBase64Encoded
.In your comment above where you say “SAM CLI only serialize the output of the container into json”, I believe you are saying that CLI serializes the
AwsProxyResponse
, if this is true, then it would appear that CLI’s serialization of it is the cause of this.There is a ticket on this problem over at serverless java container… https://github.com/awslabs/aws-serverless-java-container/issues/262