"An overwritten S3 file is gone forever." In a plain bucket, that's true: upload a new object with the same key and the old bytes are replaced. But turn on S3 Versioning and a bad overwrite or an accidental delete becomes something you can undo in a minute.
What versioning does
With versioning enabled, S3 keeps every version of every object in the bucket. Each version gets its own version ID. There is always one current version (the one a normal GET returns) and zero or more noncurrent versions behind it.
- Overwrite: uploading to the same key creates a new current version. The previous one becomes noncurrent and is still there.
- Delete (without a version ID): S3 doesn't remove anything. It adds a delete marker on top, so the object looks gone. Delete the marker and the previous version is current again.
- Delete a specific version ID: this one is permanent. That's why you protect it with permissions, and optionally MFA delete.
The three bucket states
A bucket is unversioned (the default), versioning-enabled, or versioning-suspended. Once you enable versioning, the bucket can never go back to unversioned: you can only suspend it, which stops new versions from being created but keeps the ones you have. Objects that were already there keep the version ID null; new writes get real version IDs.
Versioning is also a requirement for other features, such as S3 replication and S3 Object Lock.
What it costs, and how to keep it in check
Each version is a full copy of the object, not a diff. Three versions of a 1 GB file are billed as 3 GB. A bucket that's overwritten every hour can grow fast without anyone noticing, because a normal listing only shows current versions.
The fix is a lifecycle rule:
- NoncurrentVersionExpiration deletes old versions a number of days after they become noncurrent, for example 30.
- NewerNoncurrentVersions keeps the last few versions (1 to 100) regardless of age.
- ExpiredObjectDeleteMarker cleans up delete markers that no longer hide anything.
A common mistake: enabling versioning on a bucket that already had an expiration rule. Expiration now only adds delete markers, so storage keeps growing until you add a noncurrent-version rule.
Restoring a previous version
AWS recommends copying the version you want back onto the same key. The copy becomes the new current version and the full history stays intact. In the console, show versions, pick the one you want and copy it; with the CLI, use aws s3api copy-object with --copy-source bucket/key?versionId=.... The alternative, deleting newer versions until the old one is current, works too, but it destroys history and can race with lifecycle rules.
Where AI fits
Data pipelines overwrite files all the time: a nightly job rewrites train.parquet, a buggy transform writes empty rows, and the next training run silently learns from bad data. With versioning on the dataset bucket, rolling back is a copy of yesterday's version, not a rebuild from source systems. You can also record the version ID of the exact dataset each model was trained on, which makes a training run reproducible later. Keep a noncurrent-version lifecycle rule in place so those large files don't multiply your storage bill.
Quick recap
- Versioning keeps every version of every object; overwrites create new versions and deletes add a delete marker.
- It's off by default, and once enabled it can only be suspended, never fully turned off.
- Every version is billed in full: pair versioning with a lifecycle rule that expires noncurrent versions.