read file from s3 bucket javascript code example
Example 1: node js read file from s3 bucket
# This function for read/download file from s3 bucketconst s3download = function (params) { return new Promise((resolve, reject) => { s3.createBucket({ Bucket: BUCKET_NAME }, function () { s3.getObject(params, function (err, data) { if (err) { reject(err); } else { console.log("Successfully dowloaded data from bucket"); resolve(data); } }); }); });}
Example 2: get latest file from s3 bucket javascript
aws s3api list-objects-v2 --bucket "my-awesome-bucket" --query 'sort_by(Contents, &LastModified)[-1].Key' --output=text