S3 Versioning, delete markers and MFA delete explained
The Amazon S3 User Guide says that in a versioning-enabled bucket a delete without a version ID does not remove the object. S3 adds a delete marker, which becomes the current version, and the earlier versions stay. A bucket can be unversioned, versioning-enabled or versioning-suspended, and once enabled it can never return to unversioned.
What does a delete do in a versioned bucket?
A simple DELETE request, one that names no version ID, makes S3 insert a delete marker. The marker has a key and a version ID but no data. It becomes the current version, so S3 behaves as if the object is gone.
A GET without a version ID then returns 404 (Not Found) with the header x-amz-delete-marker: true. The earlier versions are still stored. A GET that names a version ID retrieves that specific version, so an older version can be read without touching the marker.
Overwriting an object creates a new version in the same way. Each version is a whole object and is billed as one. Delete markers and other versions are listed only by ListObjectVersions.
What changes when versioning is suspended?
Objects stored before versioning was enabled have a version ID of null. Enabling versioning does not change them; it changes how S3 handles later requests.
Suspending versioning stops the bucket from accruing new versions and leaves existing versions as they are. Every object stored after that gets the version ID null. If a null version of that key already exists, the new object overwrites its contents. Versions with real version IDs are not overwritten.
So in a suspended bucket, an object that only ever had a null version can be lost to an overwrite, while an object that gained versions during the enabled period keeps them.
Who can turn on MFA delete?
MFA delete adds a second factor to two operations: changing the versioning state of the bucket and permanently deleting an object version. The request must carry the security credentials plus the device serial number, a space and the six-digit code.
Only the bucket owner (the root account) can enable MFA delete. It cannot be enabled in the AWS Management Console; you must use the AWS CLI or the API. It is set through the same versioning configuration as the bucket's versioning status. MFA delete cannot be used with lifecycle configurations.
Where the exam catches people
Believing a delete in a versioned bucket removes the data: a delete without a version ID only adds a delete marker.
Believing suspending versioning removes old versions or makes the bucket unversioned: existing versions stay, and a bucket never returns to unversioned.
Believing a suspended bucket still protects every overwrite: new uploads get the null version ID and overwrite an existing null version.
Trying to enable MFA delete in the console as an IAM administrator: only the bucket owner's root user can enable it, through the CLI or API.
Reading a 404 on a versioned object as data loss: check for x-amz-delete-marker: true and list the versions.