In my AWS S3 bucket, I have the same file with different versions. How can I generate a pre-signed URL for each version of the same file? I am using NodeJS AWS SDK.
CodePudding user response:
Try the following code to get the pre-signed URL for a specific version of an object in AWS S3 Bucket using NodeJS AWS SDK:
const aws = require('aws-sdk');
const AWS_SIGNATURE_VERSION = 'v4';
const s3 = new aws.S3({
accessKeyId: <aws-access-key>,
secretAccessKey: <aws-secret-access-key>,
region: <aws-region>,
signatureVersion: AWS_SIGNATURE_VERSION
});
const url = s3.getSignedUrl('getObject', {
Bucket: <aws-s3-bucket-name>,
Key: <aws-s3-object-key>,
VersionId: <aws-s3-object-version-id>
Expires: <url-expiry-time-in-seconds>
})
console.log(url)
Note: Don't forget to replace the placeholders (<...>) with actual values to make it work.