AWS Certified Developer - Associate
Storage
S3 Versioning Demo
In this lesson, we explore how Amazon S3 versioning works by creating a bucket, uploading files, and observing the differences in behavior when versioning is disabled versus enabled.
Creating a Bucket with Versioning Disabled
First, create a new S3 bucket named "versioning-demo" (or a similar name) using the default settings. Make sure that bucket versioning is disabled. With versioning off, file overwrites or deletions are permanent.
Next, open the bucket and upload a file. For this demo, we use a dummy text file named file1.txt
containing:
this is version 1
This content easily identifies the file's version.
After verifying the file details in the S3 upload interface, proceed with the upload.
Once the file is uploaded, opening it within the bucket displays "this is version 1."
Deleting the File with Versioning Disabled
When versioning is disabled, deleting a file removes it permanently. To demonstrate, select the file and click "Delete." Confirm the prompt for permanent deletion.
After deletion, the file is permanently removed. To continue the demonstration, re-upload file1.txt
with the same content to restore it as version one.
Overwriting a File (Versioning Disabled)
To show how file overwrites work without versioning, open your text file and change its content to indicate an updated version:
this is version 2
Save and re-upload the file to the S3 bucket. Since the file key remains the same, the new upload overwrites the existing file. When you view file1.txt
, it now displays "this is version 2"; the original version one is permanently lost.
Enabling Bucket Versioning
Now, let's enable bucket versioning to observe the changes in file management. Go to the bucket properties, navigate to the bucket versioning section, click "Edit," and enable versioning.
With versioning enabled, re-upload the original file (file1.txt
) with the content:
this is version 1
Although the file appears unchanged, the "Show versions" option now appears, revealing a unique version ID for the file. Each subsequent overwrite will create a new version.
To update the file, modify the content to indicate version two:
this is version 2
Upload the file again using the same key. If the console does not immediately reflect changes, click "Show versions" to see two entries: the older version (version one) and the latest version (version two).
You can verify each version by opening them: version two shows "this is version 2," while version one still contains "this is version 1." Next, modify the file for version three:
this is version 3
Upload the file again. Your bucket now contains three versions of the file, with version three as the current version returned when accessing file1.txt
.
Deleting with Versioning Enabled
With versioning active, file deletion behaves differently. Select file1.txt
and click the "Delete" button. The confirmation prompt will now only ask for a simple delete confirmation rather than a permanent deletion.
When you delete the file in this mode, Amazon S3 adds a delete marker instead of permanently removing the object. Although the file may appear deleted, all previous versions remain accessible by enabling "Show versions."
Restoring a File
To restore the file, simply delete the delete marker. Select the marker and confirm its permanent deletion.
You can also selectively delete a specific version (for example, version two) by choosing that version and confirming its permanent deletion. Once a version is deleted, it cannot be recovered.
Suspending Bucket Versioning
It is important to note that once enabled, bucket versioning cannot be disabled—only suspended. To suspend versioning, return to the bucket properties, edit the versioning configuration, select "Suspend," and confirm.
Suspending versioning leaves all existing version entries intact. However, any new uploads for existing keys will be stored with a version ID of null. For example, update file1.txt
to create version four:
this is version 4
After uploading, you'll notice the new version has a version ID of null. Subsequent updates (e.g., version five) will replace the file with a null version ID, though older versions remain stored in the bucket.
Uploading a New Object with a Different Key
To see the behavior for objects with unique keys under suspended versioning, create and upload a new file named file2.txt
with the content:
this is version 1
Since versioning is suspended, this file will be stored with a null version ID. If you later modify and upload file2.txt
with new content:
this is version 2
The new upload will also have a null version ID and will replace the previous instance.
Multi-Factor Authentication (MFA) Delete
MFA Delete adds an extra layer of security by requiring multi-factor authentication for any changes to the versioning state. Note that MFA Delete can only be enabled via the AWS CLI or an SDK and is not available in the AWS Management Console. For more details, refer to the AWS documentation.
Clean Up
After completing this demonstration, clean up your S3 resources by ensuring all object versions have been shown and then deleting every object in the bucket before finally deleting the bucket.
This concludes the S3 versioning demonstration.
Watch Video
Watch video content
Practice Lab
Practice lab