I want to return an image from lambda. AWS API gateway assume that returned content is text and re-encodes it using utf-8, which corrupts response with binary content. There are two writeups, one by AWS and one by Serverless about how to turn this feature off.
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html
However, it does not work. Here’s my serverless.yml
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: us-east-1
memorySize: 128
role: arn:aws:iam::xxxxxxxxxxxx:role/xxxxxxxxxxxxxxxxxx
environment:
ENV_NAME: develop
apiGateway:
binaryMediaTypes:
- ‘image/webp’
- ‘/’
The browser asks for image/webp and I return and image file with content type image/webp. Still the API gateway tries to encode it as utf-8, adding bytes infront
of some other bytes. I also tried to remove ‘image/webp’ from serverless.yml leaving only ‘/’, but it did not help.
After deploying using npm run deploy-develop this is how it looks in AWS console
/myserverless
/ui
/{proxy+}
GET Lambda 1.0 (explicit response format)