AWS CLI get download S3 URL for private bucket from AWS CLI

Nam Nguyen picture Nam Nguyen · Jan 27, 2014 · Viewed 36.7k times · Source

I could upload a file to a private S3 bucket successfully using following command:

aws s3 cp "myfile.txt" "s3://myfolder/myfile.txt" --region=us-east-1 --output=json

I would like to issue a AWS CLI command to return me a temporary URL download for myfile.txt and does anyone know how to?

I googled and look like I have to do some signing to get temporary URL such as: http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html

Answer

ChillarAnand picture ChillarAnand · Jul 4, 2017

aws cli now supports presign command. You can run

$ aws s3 presign s3://test-bucket/test-file.txt
https://test-bucket/test-file.txt?Expires=1499152189&Signature=some-sha

This will generate an url which you can share it with anyone to download that file in 3600 seconds.

You can change time period with --expires-in

$ aws s3 presign s3://test-bucket/test-file.txt --expires-in 600 

The generated url will expire in 10 minutes.

You can read more about presign in aws cli docs.