Get an S3 Presigned Url with AWS CLI


Borislav Hadzhiev

Last updated: Sep 30, 2021


Check out my new book

How to get an S3 Presigned Url with AWS CLI #

To get an S3 presigned URL using the AWS CLI, invoke the aws s3 presign s3://my-bucket/file.txt command, where you specify the entire path of the object in the S3 URI.

aws s3 presign s3://YOUR_BUCKET/your-file.txt

get presigned url

By default the presigned url is valid for 3600 seconds, which is 60 minutes.

If you click on the URL, you will see the contents of the file in your browser.

Note that the full path to the object has to be specified, including the extension, if the file has one, e.g. s3://YOUR_BUCKET/your-folder/your-file.txt

To configure when the presigned url should expire, use the --expires-in parameter. It allows us to specify the number of seconds the presigned url should be valid for.

aws s3 presign s3://YOUR_BUCKET/your-file.txt --expires-in 10

get presigned url with expiration

In the example above, the presigned URL will only be valid for 10 seconds. If the url is accessed after 10 seconds, it returns an AccessDenied error.

presigned url expired error

Note that the s3 presign command only generates GET presigned urls, if you want to upload files to an S3 bucket using POST or PUT presigned urls, you have to use the AWS SDK.

To learn more about uploading files to an S3 bucket, using presigned urls, check out my other articles:

Further Reading #

Use the search field on my Home Page to filter through my more than 3,000 articles.