Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I have a simple question: How do I download an image from an S3 bucket to Lambda function temp folder for processing? Basically, I need to attach it to an email (this I can do when testing locally).

I have tried:

s3.download_file(bucket, key, '/tmp/image.png')

as well as (not sure which parameters will help me get the job done):

s3.getObject(params, (err, data) => {

    if (err) {


        const message = `Error getting object ${key} from bucket ${bucket}.`;



    } else {

        console.log('CONTENT TYPE:', data.ContentType);

        callback(null, data.ContentType);



Like I said, simple question, which for some reason I can't find a solution for.

1 Answer

0 votes
by (44.4k points)

Use AWS S3 API to get the image, then use fs to write it to the tmp folder.

var params = {   Bucket: "BUCKET_NAME",   Key: "OBJECT_KEY" };  

s3.getObject(params, function(err, data){   if (err) {

    console.error(err.code, "-", err.message);

    return callback(err);   }

  fs.writeFile('/tmp/filename', data.Body, function(err){


      console.log(err.code, "-", err.message);

    return callback(err);   



You can learn more about Amazon S3 on AWS S3.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories