The protection mechanism: versioning and delete markers
In Amazon S3, versioning is a fundamental way to help prevent data loss caused by human error or application failures. When this feature is enabled on a bucket, new objects receive a unique version ID. Objects that were already stored have a null version ID and do not change when versioning is enabled; if future requests modify them, they receive a unique version ID. If a user deletes an object, S3 inserts a delete marker, which becomes the current version of the object, instead of permanently deleting it.
This behavior is crucial for recovery: when an application tries to read an object whose current state is a delete marker, S3 returns a 404 error, as though the object did not exist. Earlier versions may still be stored and recoverable if they have not been permanently deleted or expired under a lifecycle rule, and if the necessary permissions are available. Versioning must be enabled explicitly; by default, buckets are unversioned, and a simple deletion does permanently remove the object.
S3 can retain multiple versions of each key, but that history is not necessarily permanent: versions can be deleted explicitly or expire under lifecycle rules. Versioning therefore lets you return to an earlier version while it remains available, but does not by itself guarantee that data will remain intact.
The difference between a simple and permanent deletion
Distinguishing a simple deletion from a permanent one is essential to avoiding catastrophic data loss. In a bucket with versioning enabled, a simple deletion—one that does not specify a versionId—adds a delete marker without permanently deleting existing versions. In an unversioned bucket, a simple deletion can permanently remove the object. To irreversibly delete an object version, use the DELETE operation and specify the exact versionId of the version to remove.
In the AWS console, the procedure for permanently deleting a version requires explicit confirmation: the user must enter the phrase "permanently delete". This safeguard is intended to prevent accidental deletion. Once a version has been permanently deleted, it cannot be recovered, so checking the version ID before proceeding is an important precaution.
A simple deletion is reversible as long as the previous version remains available; permanently deleting a version is not reversible. Once permanently deleted, that version cannot be recovered.
Step-by-step restoration procedure
To recover an accidentally deleted object, you can remove the current delete marker or copy an earlier version over the current key. Removing the marker may make a noncurrent version current; which version becomes current depends on the available versions and the bucket's versioning state. In the S3 console, select the object and then choose “Versions” to display all its versions and their IDs. You can also perform these operations using the AWS CLI.
With the AWS CLI, you can remove a specific delete marker using the template aws s3api delete-object --bucket BUCKET_NAME --key OBJECT_KEY --version-id DELETE_MARKER_VERSION_ID. Replace the three placeholders with real values and use an identity with the required permissions. The version ID must identify the delete marker, not a version containing data. Review the available versions before running the command: removing the marker can make an earlier version accessible again, whereas deleting a data version can destroy it permanently. Then check which version is current; the result depends on the retained history and versioning state.
Restoration alternatives
Instead of deleting the marker, you can copy the earlier version over the same key. The copy creates a new current version; it does not preserve the delete marker as the current version. This method can be useful if you want to restore the object without deleting earlier versions. The choice between the two methods depends on the retention policy. Keep in mind that stored versions and transfers can incur costs.
Cost management and lifecycle
One frequently underestimated consideration is the financial impact of versioning. Each object version is stored as a complete object, not as an incremental difference. This means that if an object has three versions, storage is charged for three objects. Standard S3 rates apply to every stored version and to transfers that take place, including transfers involving noncurrent versions.
To manage these costs, consider configuring S3 Lifecycle rules. The NoncurrentVersionExpiration action permanently deletes older versions after a specified number of days. This action is irreversible. In buckets where versioning is enabled or suspended, the Expiration action applies to the current version: rather than deleting it, S3 retains it as a noncurrent version and adds a delete marker, which becomes the current version. Earlier versions may therefore remain, subject to their own retention rules.
Lifecycle planning should balance the need for recovery against cost efficiency. A short retention period for noncurrent versions can reduce the bill, but it also narrows the time available to detect application errors. Teams should set these parameters according to data criticality and deployment frequency.
Versioning limits and advanced protection
Versioning helps recover objects after accidental deletions or overwrites, but it does not, on its own, prevent versions from being permanently deleted. S3 Object Lock adds a layer of protection by preventing locked versions from being deleted or overwritten during the defined retention period.
Object Lock operates under a WORM (Write-Once-Read-Many) model and automatically enables versioning when activated. It offers two retention modes: governance mode, which lets users with special permissions modify retention, and compliance mode, which prevents the protected version from being modified or deleted during the retention period, even by the account root user. Cohasset Associates has assessed S3 Object Lock for environments subject to regulations such as SEC 17a-4 or FINRA; consult that assessment for its scope.
Implementing Object Lock requires careful planning because locked versions cannot be deleted until their retention period expires. Teams must therefore define retention durations precisely to avoid accumulating obsolete data that cannot be purged. When combined with suitable configuration and other controls, versioning and Object Lock can strengthen protection against accidental or malicious deletion.