Skip to content

Instantly share code, notes, and snippets.

@bearzk
Created January 26, 2022 21:34
Show Gist options
  • Save bearzk/385c6c77e8b09126695df16f4b48d8c0 to your computer and use it in GitHub Desktop.
Save bearzk/385c6c77e8b09126695df16f4b48d8c0 to your computer and use it in GitHub Desktop.
an simple example script for generating presigned url with aws-sdk v3
// system imports
// 3rd party imports
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3')
// local imports
const client = new S3Client({
region: 'eu-west-1', // region, since s3 is global, guess it doesn't really matter :)
credentials: { // this credential should have read access to the bucket/object you want to grant temp access to the user
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
}
});
const command = new GetObjectCommand({
Bucket: 'bucket-name',
Key: 'path/to/your/private/object-file.zip',
});
const main = async () => {
const url = await getSignedUrl(client, command, { expiresIn: 60 });
console.log(url);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment