How to Send an Image as a Response via AWS Lambda and API Gateway?

exports.handler = (event, context, callback) => {
const fs = require(‘fs’);
var image = fs.readFileSync(‘./car.png’);
var response = {
statusCode: 200,
headers:
{
“Content-Type”: “image/png”
},
body: image.toString(‘base64’),
isBase64Encoded: true
};
callback(null, response);
}

aws apigateway update-integration-response \
— rest-api-id XXX \
— resource-id YYY \
— http-method GET \
— status-code 200 \
— patch-operations ‘[{“op” : “replace”, “path” : “/contentHandling”, “value” : “CONVERT_TO_BINARY”}]’
aws apigateway update-rest-api — rest-api-id XXX — patch-operations ‘[{“op” : “replace”, “path” : “/binaryMediaTypes/*~1*”, “value” : “*~1*”}]’

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store