Created
January 26, 2022 21:34
-
-
Save bearzk/385c6c77e8b09126695df16f4b48d8c0 to your computer and use it in GitHub Desktop.
an simple example script for generating presigned url with aws-sdk v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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