S3 Commands
# List existing buckets
$ aws s3 ls
# Create the S3 bucket
$ aws s3 mb s3://mybucket
# List objects in my bucket
$ aws s3 ls s3://my-bucket
# Delete a file
$ aws s3 rm s3://my-bucket/my-file.txt
# Download a file
$ aws s3 cp s3://my-bucket/my-file.txt my-file.txt
# Upload a file
$ aws s3 cp my-file.txt s3://my-bucket/my-file.txt
# Recursive uploads and downloads of multiple files in a single folder-level
$ aws s3 cp myfolder s3://mybucket/myfolder --recursive
# Synchronize the contents of a local folder to a copy in an S3 bucket
$ aws s3 sync myfolder s3://mybucket/myfolder --exclude *.tmp
Admin Commands
# Create a bucket
aws s3api create-bucket --bucket my-bucket --region us-east-1
# List buckets
aws s3api list-buckets
# Delete a bucket
aws s3api delete-bucket --bucket my-bucket
Notes
s3 ls vs s3api list-buckets
-
aws s3 ls
: This command is part of the high-level (s3) commands provided by the AWS CLI. It lists all the S3 buckets when used without any arguments, and when used with a bucket name, it lists all the objects within that bucket. The output is simpler and more human-readable.
-
aws s3api list-buckets
: This command is part of the low-level (s3api) commands provided by the AWS CLI. It lists all the S3 buckets in your AWS account, and provides more detailed information about each bucket, such as creation date. The output is in JSON format, which is more machine-readable and can be useful for scripting purposes.