AWS S3 CLI – Cheat sheet

Below is the cheat sheet of AWS CLI commands for S3.

If you are new to S3 it’s recommended that you go through this free AWS S3 crash course.

If you want to know how to install AWS CLI, follow steps on this post.

Get help

aws s3 help

or

aws s3api help

Create bucket

aws s3 mb s3://bucket-name 

Removing bucket

aws s3 rb s3://bucket-name

To remove a non-empty bucket (Extremely careful while running this). This will remove all contents in the bucket including subfolders and data in them.

aws s3 rb s3://bucket-name --force

Copy object

aws s3 cp mypic.png s3://mybucket/

Copy buckets

End the year strong with courses as low as $11.99
aws s3 cp myfolder s3://mybucket/myfolder --recursive

(Note: –recursive will copy recursively everything including the subfolders)

Sync buckets

 aws s3 sync <source> <target> [--options]

More examples of using sync and cp commands in this post.

List buckets

aws s3 ls

List specific bucket

aws s3 ls s3://mybucket

Bucket location

aws s3api get-bucket-location --bucket <bucket-name>

Logging status

aws s3api get-bucket-logging --bucket <bucket-name>

ACL (Access Control List)

The following example copies an object into a bucket. It grants read permissions on the object to everyone and full permissions (read, readacl, and writeacl) to the account associated with user@example.com.

aws s3 cp file.txt s3://my-bucket/ --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers full=emailaddress=user@example.com

 

Leave a Reply

Your email address will not be published. Required fields are marked *