Useful AWS CLI commands for S3

The AWS CLI (Command Line Interface) is a unified tool to manage your AWS services. With the AWS CLI, you can perform operations on AWS services such as Amazon S3, Amazon EC2, Amazon DynamoDB, and many others, directly from the command line. This can be useful for automating tasks, performing bulk operations, or just simplifying interaction with AWS services.

List all S3 buckets

aws s3 ls

Create a new S3 bucket

aws s3 mb s3://<s3-bucket-name>

Delete an S3 bucket

aws s3 rb s3://<s3-bucket-name>

Upload a file to an S3 bucket

aws s3 cp <your-local-file-path> s3://<s3-bucket-name>/<s3-object_key>

Download an object from an S3 bucket

aws s3 cp s3://<s3-bucket-name>/<s3-object-key> <your-local-file-path>

List the contents of an S3 bucket

aws s3 ls s3://<s3-bucket-name>

Delete an object from an S3 bucket:

aws s3 rm s3://<s3-bucket-name>/<s3-object-key>

Copy an object from one S3 bucket to another:

aws s3 cp s3://<source-s3-bucket>/<s3-object-key> s3://<destination-s3--bucket>/<s3-object-key>

Synchronize the contents of a local directory with an S3 bucket:

aws s3 sync <your-local-directory-path> s3://<s3-bucket-name>/<prefix>