Although I am able to upload file to s3 bucket by using access key and secret key. AND I am trying to upload a file to AWS s3 bucket without using access key and secret key. Please assist me. Here is my code,
import {path} from "path";
const fs = require('fs');
const AWS = require('aws-sdk');
AWS.config.update({region: 'Region'});
// Enter copied or downloaded access ID and secret key here
const ID = 'id';
const SECRET = 'id';
// The name of the bucket that you have created
const BUCKET_NAME = 'name';
const s3 = new AWS.S3({
accessKeyId: ID,
secretAccessKey: SECRET
});
const FILE_PATH = 'filepath';
const uploadFile = (fileName) => {
// Read content from the file
const fileContent = fs.readFileSync(fileName);
// Setting up S3 upload parameters
const params = {
Bucket: BUCKET_NAME,
Key: path.basename(FILE_PATH), // File name you want to save as in S3
Body: fileContent
};
// Uploading files to the bucket
s3.upload(params, function(err, data) {
if (err) {
throw err;
}
console.log('File uploaded successfully. ${data.Location}');
});
};
uploadFile(FILE_PATH);