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
You can use cp to copy the files from an s3 bucket to your local system. Use the following command: $ aws s3 cp s3://bucket/folder/file.txt .
You can download an object from an S3 bucket in any of the following ways: Select the object and choose Download or choose Download as from the Actions menu if you want to download the object to a specific folder. If you want to download a specific version of the object, select the Show versions button.
Restrict access to your S3 resources. By default, all S3 buckets are private and can be accessed only by users who are explicitly granted access. Restrict access to your S3 buckets or objects by doing the following: Writing IAM user policies that specify the users that can access specific buckets and objects.
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.
You can use the following URL format:
https://<bucket-name>.s3.amazonaws.com/<object or key name>
or old style:
https://s3.amazonaws.com/<bucket-name>/<object or key name>
To have it accessible you need to allow public access to your object or attach an appropriate bucket policy.
For example the following bucket policy shows public access to bucket zzzyyy
object 'yyyeee'
$ aws s3 get-object-acl --bucket zzzyyy --key yyyeee { "Owner": { "DisplayName": "owner", "ID": "Some hash of owner" }, "Grants": [ { "Grantee": { "DisplayName": "owner", "ID": "Some hash of owner" }, "Permission": "READ" }, { "Grantee": { "DisplayName": "owner", "ID": "Some hash of owner" }, "Permission": "WRITE" }, { "Grantee": { "DisplayName": "owner", "ID": "Some hash of owner" }, "Permission": "READ_ACP" }, { "Grantee": { "DisplayName": "owner", "ID": "Some hash of owner" }, "Permission": "WRITE_ACP" }, { "Grantee": { "URI": "http://acs.amazonaws.com/groups/global/AllUsers" }, "Permission": "READ" }, { "Grantee": { "URI": "http://acs.amazonaws.com/groups/global/AllUsers" }, "Permission": "READ_ACP" } ] }
You can see examples of bucket policies here:
http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage_UseCases_s3_a.html
You can also use the S3 Console as seen here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With