Serving binary files via API Gateway from Lambda function
To make the API gateway serve binary files for the specific content type it can easily be configured in the API gateway: API settings.
Afterwards configuring the integration type for the specific endpoint needs to be Lambda function with Lambda proxy integration turned on.
The important part when configuring API Gateway to serve binary files is setting Content-Type
header for the client making request to the API gateway to match the media format set in the API Gateway configuration.
This way when a request comes with the Content-Type
header set, if it matches the Content-Type
set in the API gateway Binary media type, the API gateway will return binary files to the client.
To serve binary files without the client sending the correct Content-Type
header, API Gateway Binary media types need to be set to */*
this way all responses will be sent as binary.