2
votes

I have a problem whereby my API Gateway + Lambda Integration is undergoing some form of content mapping by the API Gateway.

I have API Gateway with an endpoint which is using the Lambda Proxy Integration.

I have enabled the Binary Media Types: image/jpeg image/png image/webp image/* /

The endpoint takes an images, optimizes it to jpeg or webp depending on what browser you are using.

With Firefox it returns the image/jpeg as expected.

Viewing in Chrome (which returns the webp file) results in a square box being returned. (This all works on Elastic Beanstalk, so I know it is a gateway problem)

In Chrome I can see some sort of mapping is happening:

content-length: 4710
content-type: image/webp
status: 200
x-amz-apigw-id: UEG2ZE8vDoEFR8A=
x-amzn-remapped-content-length: 2580
x-amzn-requestid: 6217195f-20ae-11e9-9faf-ebf6a6f5765d
x-amzn-trace-id: Root=1-5c4b1e8f-cab2e4fd2564412ef5914509;Sampled=0

The value: x-amzn-remapped-content-length Is the length that should be returned. I'm not sure what processes is skewing the return of the data.

Proxy Integration Setup Proxy Integration Setup

API Gateway Configuration API Gateway Configuration

1

1 Answers

1
votes

For anyone else stuck on this issue, I needed to register the binary types in my Lambda Entry Point, see below:

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
    protected override void Init(IWebHostBuilder builder)
    {
        // Register any MIME content types you want treated as binary
        RegisterResponseContentEncodingForContentType("image/jpeg", ResponseContentEncoding.Base64);
        RegisterResponseContentEncodingForContentType("image/webp", ResponseContentEncoding.Base64);
        RegisterResponseContentEncodingForContentType("image/png", ResponseContentEncoding.Base64);

        builder
            .UseStartup<Startup>();
    }
}