AWS CLI S3 Commands
AWS CLI S3 commands allow you to create buckets, upload and download files, manage objects, and organize storage directly from the terminal.
Official Link: https://docs.aws.amazon.com/cli/latest/reference/s3/
Create & Manage Buckets
a) Create bucket
Bash
aws s3 mb s3://my-new-bucket
If the bucket is created successfully, it returns:
make_bucket: my-new-bucket
b) Create bucket in specific region
Bash
aws s3 mb s3://my-new-bucket --region ap-south-1
c) List buckets
To list all buckets in your account:
Bash
aws s3 ls
d) Remove bucket (must be empty)
Bash
aws s3 rb s3://my-new-bucket
If the bucket is deleted successfully:
remove_bucket: my-new-bucket
If the bucket is not empty, deletion fails:
remove_bucket failed: s3://my-new-bucket/ An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty
So, delete objects first and then delete the bucket:
Bash
aws s3 rm s3://my-new-bucket --recursive aws s3 rb s3://my-new-bucket
Upload Files
To upload files from your local system to an S3 bucket:
a) Upload single file
Bash
aws s3 cp file.txt s3://mybucket/
b) Upload entire workspace
Bash
aws s3 cp "." s3://bucket-567/ --recursive
Download Files
a) Download file
Bash
aws s3 cp s3://mybucket/file.txt .
b) Download folder
To download all files from a folder, use the --recursive option.
Bash
aws s3 cp s3://mybucket/myfolder . --recursive
Delete Files
The rm command removes objects from an S3 bucket.
Basic Syntax
aws s3 rm <S3_PATH>
a) Delete file
Bash
aws s3 rm s3://mybucket/file.txt
- Deletes file.txt from the bucket.
- Only that object is removed.
Note: If the file does not exist, the command does not throw an error.
b) Delete folder (All files inside)
S3 does not have real folders — they are object prefixes. To remove all objects inside a folder, use --recursive.
Bash
aws s3 rm s3://mybucket/folder/ --recursive
- Deletes all files inside folder/.
- Removes nested subfolders and contents.
Move Files
The aws s3 mv command is used to move or rename files and folders between locations.
- Local system → S3
- S3 → Local system
- S3 → S3
- Within the same bucket (rename or reorganize)
Unlike cp, the source file is deleted after transfer.
Basic Syntax
aws s3 mv <source> <destination>
👉 Think of it as:
move = copy + delete source
a) Upload and remove local file
Bash
aws s3 mv report.pdf s3://mybucket/
- Uploads the file.
- Deletes the local file.
b) Move file: S3 → Local
Bash
aws s3 mv s3://mybucket/report.pdf .
- Downloads the file.
- Removes it from S3.
c) Move file: S3 → S3
Bash
aws s3 mv s3://bucket-a/file.txt s3://bucket-b/