2020-06-30 15:51:03 +01:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2024-01-16 10:41:11 -05:00
/*
2020-06-30 15:51:03 +01:00
ABOUT THIS NODE.JS SAMPLE: This sample is part of the Amazon S3 Developer Guide topic at
https://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjectPreSignedURLJavaScriptSDK.html
Purpose:
2022-06-20 18:27:40 +01:00
s3_getsignedURL.js demonstrates how to generate a presigned URL that a non-authenticated user
can use to retrieve (get) an object to an Amazon S3 bucket.
2020-06-30 15:51:03 +01:00
Inputs:
- REGION (into command line below)
- BUCKET_NAME (into command line below)
- FILE_NAME (into command line below)
- EXPIRATION (into code; in seconds, e.g., 60*5)
Running the code:
2022-06-20 18:27:40 +01:00
node s3_getsignedURL.js REGION BUCKET_NAME FILE_NAME
2020-06-30 15:51:03 +01:00
*/
// snippet-start:[s3.JavaScript.presignedURL.complete]
const AWS = require ( "aws-sdk" ) ;
// Set the AWS region
const region = process . argv [ 2 ] ; // REGION
AWS . config . update ( region ) ;
// Create S3 service object
const s3 = new AWS . S3 ( ) ;
// Set the parameters
const myBucket = process . argv [ 3 ] ; //BUCKET_NAME
const myKey = process . argv [ 4 ] ; // FILE_NAME
const signedUrlExpireSeconds = 60 * 5 ; //EXPIRATION
const presignedURL = s3 . getSignedUrl ( "putObject" , {
Bucket : myBucket ,
Key : myKey ,
Expires : signedUrlExpireSeconds ,
} ) ;
console . log ( presignedURL ) ;
2021-06-09 17:13:33 +01:00
// snippet-end:[s3.JavaScript.presignedURL.complete]