Categories
JavaScript Answers

How to create an AWS Lambda function to write to S3with Node.js?

Spread the love

Sometimes, we want to create an AWS Lambda function to write to S3with Node.js.

In this article, we’ll look at how to create an AWS Lambda function to write to S3with Node.js.

How to create an AWS Lambda function to write to S3with Node.js?

To create an AWS Lambda function to write to S3with Node.js, we can call putObject.

For instance, we write

var AWS = require("aws-sdk");
const putObjectToS3 = (bucket, key, data) => {
  const s3 = new AWS.S3();
  const params = {
    Bucket: bucket,
    Key: key,
    Body: data,
  };
  s3.putObject(params, (err, data) => {
    //...
  });
};

to create the putObjectToS3 function.

In it, we call s3.putObject with the info in the params object to push our file, which is stored in data, to the location with the given bucket and key.

Conclusion

To create an AWS Lambda function to write to S3with Node.js, we can call putObject.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *