Borislav Hadzhiev
Last updated: Sep 30, 2021
Check out my new book
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
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.
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
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.
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: