Skip to main content
In this guide, we’ll explore essential Amazon S3 operations—listing, creating, deleting buckets, and managing objects—using the AWS CLI. Automate your workflows and integrate these commands into scripts for seamless infrastructure management.

Prerequisites

  • AWS CLI installed and configured (aws configure)
  • IAM permissions to list, create, and delete S3 buckets and objects
  • Unique bucket names (globally unique across AWS)
Before creating a bucket, verify the name’s availability. Bucket names must be globally unique and compliant with DNS naming conventions.

Quick Reference: Common S3 CLI Commands


1. Listing S3 Buckets

Retrieve all buckets in your AWS account:

2. Creating a New Bucket

Use the make bucket command and specify a region:

3. Deleting a Bucket

Remove an empty bucket:
To delete a bucket and all its contents, add --force:
Using --force is irreversible. All objects in the bucket will be permanently deleted.

4. Listing Objects Inside a Bucket

4.1 Top-Level Listing

List prefixes (folders) and files at the root of the bucket:

4.2 Recursive Listing

Show every object under the bucket:

5. Copying Files

5.1 Local → S3

Upload a file without deleting the source:

5.2 S3 → Local

Download an object to a local directory:

5.3 S3 → S3

Copy between two buckets:

6. Deleting Objects

6.1 Single Object

6.2 Multiple Objects (Recursive)


7. Directory Operations

Most S3 CLI commands support --recursive to process all files under a directory or prefix.

7.1 Copy an Entire Directory

7.2 Move Files and Directories

Use mv to transfer and remove the source:

8. Synchronizing Directories

Keep a local folder and an S3 prefix in sync. Only new or updated files transfer:
Adding new files (for example, etc/ssh) and rerunning uploads only those:

Next Steps

You’ve mastered the core AWS S3 CLI commands for bucket and object management. Apply these operations in scripts or CI/CD pipelines to automate your workflows.

Watch Video