You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Versioning protects your data from accidental overwrites and deletions. Lifecycle policies automate the transition of objects between storage classes and their eventual expiration. Together, they form the backbone of a cost-effective and resilient storage strategy.
When versioning is enabled on a bucket, S3 keeps every version of every object. Each PUT generates a new version with a unique version ID. Deleting an object does not actually remove the data — it inserts a delete marker, which hides the current version but preserves all previous ones.
A bucket can be in one of three versioning states:
| State | Description |
|---|---|
| Unversioned | The default. No version tracking. Overwrites and deletes are permanent. |
| Enabled | Every object gets a version ID. All versions are preserved. |
| Suspended | New objects get a null version ID, but existing versions are preserved. |
Once versioning is enabled, it can be suspended but never fully disabled.
aws s3api put-bucket-versioning \
--bucket my-app-bucket \
--versioning-configuration Status=Enabled
Uploading the same key twice:
PUT photo.jpg → Version ID: v1 (original)
PUT photo.jpg → Version ID: v2 (updated)
A GET request for photo.jpg returns v2 (the latest version). You can still retrieve v1 by specifying the version ID.
Deleting an object:
DELETE photo.jpg → Delete marker added
A GET request now returns a 404, but v1 and v2 still exist. To permanently delete a specific version:
aws s3api delete-object \
--bucket my-app-bucket \
--key photo.jpg \
--version-id v1
aws s3api list-object-versions --bucket my-app-bucket --prefix photo.jpg
To restore a previous version, simply copy it back as the current version:
aws s3api copy-object \
--bucket my-app-bucket \
--copy-source my-app-bucket/photo.jpg?versionId=v1 \
--key photo.jpg
Versioning increases storage costs because every version counts towards your storage bill. Use lifecycle policies to manage old versions and control costs.
Lifecycle policies define rules that automatically transition objects between storage classes or delete them after a specified period.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.