Created
February 4, 2020 11:14
-
-
Save secretshardul/d7390ed120d54b75f152f07300aa72d2 to your computer and use it in GitHub Desktop.
Lambda function reads a file from an S3 bucket. It converts it into a base64 encoded string and returns the value. API gateway converts this into binary and adds the appropriate header.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var AWS = require("aws-sdk"); | |
var s3 = new AWS.S3(); | |
exports.handler = (event, context, callback) => { | |
var params = {Bucket: 'myBucket', Key: 'myImg.png'}; | |
s3.getObject(params, function(err, data) { | |
if (err) { | |
console.log(err, err.stack); | |
} | |
else{ | |
var attachment = data.Body.toString('base64'); | |
callback(null, attachment); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment