Reading time·2 min
To get an S3 pre-signed 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 pre-igned 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 pre-signed URL should expire, use the --expires-in
parameter. It allows us to specify the number of seconds the pre-signed URL
should be valid for.
aws s3 presign s3://YOUR_BUCKET/your-file.txt --expires-in 10
In the example above, the pre-signed 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
pre-signed URLs, if you want to upload files to an
S3 bucket using POST
or PUT
pre-signed
URLs, you have to use the AWS SDK.