read from s3 bucket nodejs

To read from an S3 bucket using Node.js, you can follow these steps:

  1. Install the AWS SDK for JavaScript using npm:
npm install aws-sdk
  1. Configure the AWS SDK with your credentials and the region where your S3 bucket is located:
const AWS = require('aws-sdk');
AWS.config.update({
  accessKeyId: 'YOUR_ACCESS_KEY_ID',
  secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',
  region: 'YOUR_REGION'
});
  1. Create an S3 object using the configured AWS SDK:
const s3 = new AWS.S3();
  1. Use the getObject method to retrieve the data from the S3 bucket. Provide the bucket name and the key of the object you want to read:
const params = { Bucket: 'YOUR_BUCKET_NAME', Key: 'YOUR_OBJECT_KEY' };
s3.getObject(params, (err, data) => {
  if (err) {
    console.error(err);
  } else {
    console.log(data.Body.toString('utf-8'));
  }
});

These steps will allow you to read data from an S3 bucket using Node.js.