# Day 23: Data Migration Between S3 Buckets Using AWS CLI
🎯 Objective
Learn how to use the AWS CLI to migrate data from one Amazon S3 bucket to another.
In this example, we will:
👉 Using the AWS CLI makes S3 data migration faster and repeatable without manually downloading and uploading files.
🧠 Concept
The AWS CLI provides high-level commands for interacting with Amazon S3.
The basic syntax is:
aws s3 <command>Common operations include:
Create bucket
List files
Copy files
Move files
Delete files
Synchronize bucketsFor bucket-to-bucket migration, the most useful command is:
aws s3 syncThe sync command compares the source and destination and copies new or updated objects to the destination.
🧰 Common AWS S3 Commands
AWS CLI provides several high-level S3 commands:
You can view the available commands using:
aws s3 help⚙️ Migration Flow
The migration process in this example is:
Source S3 Bucket
devops-s3-867
│
│ aws s3 sync
▼
Destination S3 Bucket
devops-sync-18571The AWS CLI reads objects from the source bucket and transfers them to the destination bucket.
🪣 Step 1: Create the Destination Bucket
Create a new S3 bucket:
aws s3 mb s3://devops-sync-18571 --region us-east-1Command Breakdown
aws s3 mbmb means make bucket.
s3://devops-sync-18571Specifies the bucket name.
--region us-east-1Creates the bucket in the us-east-1 AWS region.
🔍 Step 2: List S3 Buckets
Verify that the bucket was created:
aws s3 lsThis lists the S3 buckets accessible using the current AWS credentials.
Example:
2026-08-09 10:20:30 devops-s3-867
2026-08-09 10:25:42 devops-sync-18571📂 Step 3: Check the Source Bucket
Before migrating data, check the contents of the source bucket:
aws s3 ls s3://devops-s3-867To inspect all objects, including objects inside prefixes/directories:
aws s3 ls s3://devops-s3-867 --recursiveThis helps verify what data should be migrated.
🔄 Step 4: Sync Data Between Buckets
Synchronize the source bucket with the destination bucket:
aws s3 sync s3://devops-s3-867 s3://devops-sync-18571Source
s3://devops-s3-867Destination
s3://devops-sync-18571The flow is:
devops-s3-867
│
│ aws s3 sync
▼
devops-sync-18571AWS CLI compares the source and destination and transfers objects that need to be synchronized.
🧠 sync vs cp
Both cp and sync can transfer S3 objects, but they serve different purposes.
Copy
aws s3 cp s3://source-bucket/file.txt s3://destination-bucket/file.txtBest when copying:
For recursive copying:
aws s3 cp s3://source-bucket s3://destination-bucket --recursiveSync
aws s3 sync s3://source-bucket s3://destination-bucketBest when:
For bucket migration, sync is usually more convenient.
🔍 Step 5: Verify the Source Bucket
Check the original bucket:
aws s3 ls s3://devops-s3-867For a complete recursive listing:
aws s3 ls s3://devops-s3-867 --recursive🔍 Step 6: Verify the Destination Bucket
Check the migrated bucket:
aws s3 ls s3://devops-sync-18571You should see the synchronized objects.
For example:
2026-08-09 10:30:21 12543 image.jpg
2026-08-09 10:30:22 4231 config.json
2026-08-09 10:30:23 182392 backup.sql📊 Step 7: Check All Migrated Objects
Use --recursive to list every object:
aws s3 ls s3://devops-sync-18571 --recursiveThis is useful when the bucket contains nested prefixes such as:
images/
documents/
backups/
logs/📈 Step 8: Check Migration Summary
Use:
aws s3 ls s3://devops-sync-18571 --recursive --summarizeAt the bottom of the output, AWS CLI displays a summary similar to:
Total Objects: 125
Total Size: 524288000This helps verify:
You can run the same command against the source:
aws s3 ls s3://devops-s3-867 --recursive --summarizeThen compare the source and destination.
Source Bucket Destination Bucket
│ │
▼ ▼
Total Objects: 125 Total Objects: 125
Total Size: 524288000 Total Size: 524288000Matching totals provide a useful basic verification that the expected data was transferred.
🗑️ Optional: Make Destination Match Source
By default:
aws s3 sync s3://source-bucket s3://destination-bucketdoes not necessarily remove extra objects already present in the destination.
To make the destination more closely mirror the source:
aws s3 sync \
s3://devops-s3-867 \
s3://devops-sync-18571 \
--delete⚠️ Be careful with --delete.
Objects existing in the destination but not in the source can be deleted.
Always verify the source and destination before using it.
🔐 Required Permissions
The AWS credentials running the migration need appropriate permissions.
Typical permissions include:
s3:ListBucket
s3:GetObject
s3:PutObjectDepending on the operation, additional permissions may be required.
Conceptually:
Source Bucket
│
│ GetObject
▼
AWS CLI
│
│ PutObject
▼
Destination BucketIf permissions are missing, you may encounter errors such as:
AccessDenied⚠️ Important Notes
🧪 Validation Checklist
🔗 Reference
AWS CLI S3 Command Reference:
https://docs.aws.amazon.com/cli/latest/reference/s3/
Useful commands:
aws s3 cp
aws s3 ls
aws s3 mb
aws s3 mv
aws s3 presign
aws s3 rb
aws s3 rm
aws s3 sync
aws s3 website📌 Summary
AWS CLI provides a simple way to migrate data directly between S3 buckets.
Instead of:
S3 Source
↓
Download files locally
↓
Upload files manually
↓
S3 Destinationwe can use:
Source Bucket
devops-s3-867
│
│ aws s3 sync
▼
Destination Bucket
devops-sync-18571The core migration command is:
aws s3 sync s3://devops-s3-867 s3://devops-sync-18571Then verify the result using:
aws s3 ls s3://devops-sync-18571 --recursive --summarizeThis provides a simple, repeatable, and CLI-based approach to S3 bucket data migration.