AWS CLI S3 Cheat Sheet

High-level and low-level AWS CLI S3 commands for buckets, objects, sync, versioning, encryption, and presigned URLs.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## High-Level S3 Commands
List buckets
aws s3 ls

# List S3 buckets in the account.

List objects in a bucket
aws s3 ls s3://my-bucket/

# List top-level objects and prefixes in a bucket.

Upload a file to S3
aws s3 cp ./app.log s3://my-bucket/logs/app.log

# Copy a local file into a bucket.

Download a file from S3
aws s3 cp s3://my-bucket/backups/db.dump ./db.dump

# Copy an object from S3 to local disk.

Upload a directory recursively
aws s3 cp ./dist s3://my-bucket/site/ --recursive

# Copy a local directory tree to S3.

Sync local directory to S3
aws s3 sync ./public s3://my-bucket/public/

# Synchronize a local directory to a bucket prefix.

Mirror local directory to S3 with deletes
aws s3 sync ./public s3://my-bucket/public/ --delete

# Delete extra destination objects during sync.

Delete an object
aws s3 rm s3://my-bucket/tmp/data.csv

# Remove a single object from S3.

Delete a prefix recursively
aws s3 rm s3://my-bucket/tmp/ --recursive

# Remove all objects under a prefix.

Move or rename an object
aws s3 mv s3://my-bucket/tmp/file.txt s3://my-bucket/archive/file.txt

# Move an object within S3 or between S3 and local paths.

## S3API Bucket Commands
Create a bucket
aws s3api create-bucket --bucket my-bucket --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2

# Create a new bucket using the low-level API command.

Check whether a bucket exists
aws s3api head-bucket --bucket my-bucket

# Probe a bucket with HEAD.

Get bucket region
aws s3api get-bucket-location --bucket my-bucket

# Show the bucket's region or location constraint.

Enable bucket versioning
aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration Status=Enabled

# Turn on object versioning for a bucket.

Get bucket versioning state
aws s3api get-bucket-versioning --bucket my-bucket

# Inspect the versioning configuration on a bucket.

Set default encryption
aws s3api put-bucket-encryption --bucket my-bucket --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'

# Configure bucket default server-side encryption.

Get bucket encryption config
aws s3api get-bucket-encryption --bucket my-bucket

# Read the default encryption settings on a bucket.

Block public access
aws s3api put-public-access-block --bucket my-bucket --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

# Enable all four bucket public access block settings.

Attach a bucket policy
aws s3api put-bucket-policy --bucket my-bucket --policy file://bucket-policy.json

# Set a bucket policy from a local JSON file.

Delete an empty bucket
aws s3api delete-bucket --bucket my-bucket

# Remove a bucket after it has been emptied.

## S3API Object Commands
Upload an object with s3api
aws s3api put-object --bucket my-bucket --key docs/readme.txt --body ./README.md

# Put a single object using low-level API options.

Download an object with s3api
aws s3api get-object --bucket my-bucket --key backups/db.dump ./db.dump

# Fetch an object to a local file.

Read object metadata
aws s3api head-object --bucket my-bucket --key backups/db.dump

# Inspect metadata for a specific object.

Copy an object
aws s3api copy-object --bucket my-bucket --copy-source source-bucket/path/file.txt --key copies/file.txt

# Copy an object within S3 using low-level API syntax.

Delete an object with s3api
aws s3api delete-object --bucket my-bucket --key tmp/file.txt

# Delete a single object by key.

List object versions
aws s3api list-object-versions --bucket my-bucket --prefix app/

# Show versions in a versioned bucket.

Delete a specific object version
aws s3api delete-object --bucket my-bucket --key app/config.json --version-id 3Lg..example

# Remove one version from a versioned bucket.

Generate a presigned URL
aws s3 presign s3://my-bucket/reports/monthly.pdf --expires-in 3600

# Create a temporary signed download URL for an object.

Recommended next

No recommendations yet.