← All posts
2 min read

Transition S3 objects to Standard-IA with lifecycle

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

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

What we are learning

Lifecycle transitions move eligible objects to another storage class without a manual copy operation.

Before you run it

aws sts get-caller-identity
REGION="ap-south-1"
BUCKET="replace-with-your-private-demo-bucket"

Use a private general purpose bucket that you own. Replace every placeholder before running a write or delete command.

Cost note: Transitions, retrievals, and minimum storage durations can create charges.

The command

cat > lifecycle-transition.json <<'EOF'
{
  "Rules": [{
    "ID": "MoveReportsToStandardIA",
    "Status": "Enabled",
    "Filter": {"Prefix": "reports/"},
    "Transitions": [{"Days": 30, "StorageClass": "STANDARD_IA"}]
  }]
}
EOF
 
aws s3api put-bucket-lifecycle-configuration \
  --bucket "$BUCKET" \
  --lifecycle-configuration file://lifecycle-transition.json

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

Inspect the result

aws s3api get-bucket-lifecycle-configuration \
  --bucket "$BUCKET" \
  --query "Rules[].{ID:ID,Prefix:Filter.Prefix,Days:Transitions[0].Days,Class:Transitions[0].StorageClass}" \
  --output table

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

One tiny variation

aws s3api list-objects-v2 \
  --bucket "$BUCKET" \
  --prefix reports/ \
  --query "Contents[].{Key:Key,Class:StorageClass}"

Object listings show the current storage class after S3 performs the transition asynchronously.

Common mistake

Lifecycle timing is not an exact scheduler, and storage-class minimums still matter. Model cost before applying transitions to many small or frequently read objects.

Cleanup

aws s3api delete-bucket-lifecycle --bucket "$BUCKET"
rm lifecycle-transition.json

Remove the rule during a demo. Existing transitioned objects remain in their current storage class.

Next, we will learn Expire noncurrent S3 versions with lifecycle.

Official AWS CLI reference