How to create a Pre-signed URL in S3
When you create a S3 bucket by default all the objects in the buckets you upload are privte and only the object owner has permission to access it.
However, the object owner can optionally share objects with others by creating a presigned URL, using their own security credentials, to grant time-limited permission to download the objects.
When you create a presigned URL and shared it, Anyone who receive the URL can access the objects even if the objects is private. For example if you upload a file object into the bucket and both the bucket and the file object is private, You can create the presigned URL and share it.
To create a Pre-signed URL from AWS console
Login to AWS console and select the bucket and object you want to create -pre-signed URL.Go to Actions and select share with Presigned URL option.AWS console maximum you can create presigned url with12 hours experation time.For loger time we would need to create the URL from AWS CLI/SDK.
To create a Pre-signed URL from AWS CLI
When you create presigned URL using a temporary token ( eg : from ec2 machine with instance profile attached ) the URL expires when the temporary tocken expires even if the URL was created with more expiration time.
The credentials you can use to create a presigned url include .
AWS Identity and Access Management (IAM) instance profile: Valid up to six hours.
AWS Security Token Service (STS): Valid up to 36 hours when signed by an AWS Identity and Access Management (IAM) user, or valid up to one hour when signed by the root user.
IAM user: Valid up to seven days when using AWS Signature Version 4.
If you want more expiration time for presigned URL more then 36 hours upto 7 days, i would recommed to use and configure AWS Access Key ID and AWS Secret Access Key into AWS CLI.
After Access/secret key into aws configure use below AWS CLI command to create presigned URL. Below example will create a presigned URL with max expiration of 7 days.
aws s3 presign s3://DOC-EXAMPLE-BUCKET/Drawing.zip— expires-in 604800

Top comments (0)