How to send binary response using AWS Lambda using Gateway API in Node.js?

I am trying to configure Lambda and the Gateway APIs that will do s3.getObject () and output the binary image as an answer. In the end, I would like to pull the image out of s3 and resize it on the fly instead of saving them back to s3, however I cannot get even a simple image for 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 installed binary support for the API gateway to allow 'image / jpeg', and I tried to set the content type to Response Response and Integration Response.

Method Answer: enter image description here

Integration Response: enter image description here

+4
source share
2

: API- AWS Gateway base64Decode

, AWS, CLI, Lambda Create Method.

+1

?

, Content-Type Accept

0

Source: https://habr.com/ru/post/1665941/


All Articles