AWS CLI 2 cheatsheet

AWS CLI 2: S3

8 common AWS CLI 2 tasks.

List buckets or objects

List buckets, or add a bucket and prefix to list objects.

aws s3 ls s3://my-bucket/path/

Create a bucket

Create a bucket. Names are globally unique.

aws s3 mb s3://my-unique-bucket-name

Upload a file

Copy a local file to a bucket.

aws s3 cp file.txt s3://my-bucket/

Download a file

Copy an object to the current folder.

aws s3 cp s3://my-bucket/file.txt .

Sync a folder to a bucket

Upload only new and changed files.

aws s3 sync ./dist s3://my-bucket

Mirror a folder, deleting extras

Also delete objects in the bucket that are not in the folder.

aws s3 sync ./dist s3://my-bucket --delete

Caution: Deletes objects that are missing locally. Preview with --dryrun first.

Delete everything under a prefix

Delete all objects under a prefix.

aws s3 rm s3://my-bucket/old/ --recursive

Caution: Deleted objects cannot be recovered unless versioning is enabled. Preview with --dryrun.

Create a temporary download link

Make a signed URL that expires after an hour.

aws s3 presign s3://my-bucket/file.txt --expires-in 3600

Was this page helpful?