Return binary media from a Lambda proxy integration in API Gateway
To return binary media from an AWS Lambda proxy integration, base64 encode the response from your Lambda function. You must also configure your API's binary media types. The payload size limit is 10 MB.
Note
To use a web browser to invoke an API with this example integration, set your
API's binary media types to */*
. API Gateway uses the first
Accept
header from clients to determine if a response should
return binary media. To return binary media when you can't control the order of
Accept
header values, such as requests from a browser, set your
API's binary media types to */*
(for all content types).
The following example Lambda function can return a binary image from Amazon S3
or text to clients. The function's response includes a Content-Type
header to indicate to the client the type of data that it returns. The function
conditionally sets the isBase64Encoded
property in its response,
depending on the type of data that it returns.
To learn more about binary media types, see Binary media types for REST APIs in API Gateway.