← All posts
2 min read

Prepare S3 buckets for replication

#aws#cli#s3#storage#replication#versioning
📑 On this page

Part 72 of AWS from Zero. This lesson keeps the scope to one S3 behavior you can verify from the terminal.

What we are learning

S3 replication requires versioning on both buckets. The destination, permissions role, ownership, encryption, and Region design should be settled before the rule.

Before you run it

SOURCE_BUCKET="replace-with-source-bucket"
DEST_BUCKET="replace-with-destination-bucket"

Use two general purpose buckets. Replication commonly spans Regions, so consider transfer, KMS, and storage costs.

Cost note: Replication creates destination storage and may add transfer, request, KMS, and replication-time charges.

The command

aws s3api put-bucket-versioning \
  --bucket "$SOURCE_BUCKET" \
  --versioning-configuration Status=Enabled
 
aws s3api put-bucket-versioning \
  --bucket "$DEST_BUCKET" \
  --versioning-configuration Status=Enabled

A successful configuration command may return no output. Treat inspection as a separate required step.

Inspect the result

aws s3api get-bucket-versioning --bucket "$SOURCE_BUCKET"
aws s3api get-bucket-versioning --bucket "$DEST_BUCKET"

Read the returned fields rather than assuming the write succeeded exactly as intended.

One tiny variation

aws s3api get-bucket-location --bucket "$SOURCE_BUCKET"
aws s3api get-bucket-location --bucket "$DEST_BUCKET"

Record both Regions before choosing same-Region or cross-Region replication.

Common mistake

Replication does not retroactively copy existing objects by default. Plan S3 Batch Replication separately when historical objects must be copied.

Cleanup

aws s3api put-bucket-versioning \
  --bucket "$SOURCE_BUCKET" \
  --versioning-configuration Status=Suspended
aws s3api put-bucket-versioning \
  --bucket "$DEST_BUCKET" \
  --versioning-configuration Status=Suspended

Suspending affects future writes but does not remove existing versions.

Next, we will learn Create a basic S3 replication rule.

Official AWS CLI reference