I'm trying to set up a Lambda and API Gateway that will do a s3.getObject() and output the binary image as a response. Eventually I'd like to pull an image from s3 and resize on the fly instead of saving them back to s3, however I can't seem to get even a simple image to output.
My simple lambda looks like this:
'use strict';
const http = require('http');
exports.handler = (event, context, callback) => {
http.get('http://i.stack.imgur.com/PIFN0.jpg', function(res) {
var body = '';
res.on('data', function(chunk) {
// Agregates chunks
body += chunk;
});
res.on('end', function() {
callback(null, body);
});
});
};
I've set the API Gateway Binary Support to allow 'image/jpeg' and I've tried setting the Content Type in the Method Response and Integration Response.
Method Response:
Integration Response:
Under the selected API in the primary navigation panel, choose Settings. In the Settings pane, choose Add Binary Media Type in the Binary Media Types section. Type a required media type, for example, image/png , in the input text field. If needed, repeat this step to add more media types.
The Lambda execution environment is based on a specific Amazon Linux AMI and kernel version. Any native binaries that are used in a Lambda deployment package must be compiled in this environment, and only 64-bit binaries are supported.
I found my answer here: AWS Gateway API base64Decode produces garbled binary?
It requires a CLI command to change a setting that isn't exposed in the AWS Console when you select Lambda Function on the Create Method screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With