question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid API Gateway Response Keys: {'base64Encoded'} in {'statusCode': 200, 'headers': {'Content-Type': 'text/plain'}, 'body': 'Hello World', 'base64Encoded': False}

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
vladamxcommented, Jul 6, 2019

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

1reaction
kastorkcommented, Sep 30, 2020

@jfuss

Looking at the object returned by the serverless java container (AwsProxyResponse), the properties are correct.


    @JsonProperty("isBase64Encoded")
    public boolean isBase64Encoded() {
        return isBase64Encoded;
    }

    public void setBase64Encoded(boolean base64Encoded) {
        isBase64Encoded = base64Encoded;
    }

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid API Gateway Response Keys: {'base64Encoded'} in ...
Invalid API Gateway Response Keys : {'base64Encoded'} in {'statusCode': 200, 'headers': {'Content-Type': 'text/plain'}, 'body': 'Hello World' ...
Read more >
Handling binary data using Amazon API Gateway HTTP APIs
API Gateway's base64-encoding unifies the handling of text and binary data in Lambda. Binary and non-binary data is passed to a Lambda function ......
Read more >
REST API (API Gateway v1) - Serverless Framework
Use async: true when integrating a lambda function using event invocation. This lets API Gateway to return immediately with a 200 status code...
Read more >
HTTP - Developers - Dropbox.com
The Dropbox API allows developers to work with files in Dropbox, ... Depending on the status code, the response body may be in...
Read more >
AWS API Gateway: why post request body is encoded base64?
If I am understanding your question correct, you are sending non base64 encoded JSON payload as request to API gateway, however your Lambda ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found