Bucket Versioning

Introduction

Cost Consideration: Each version of an object is stored as a complete copy, not just differences. If you have 3 versions of a file, you pay for 3 complete files. AWS charges normal S3 rates for every version stored and transferred. Consider using lifecycle policies to manage old versions.

What is S3 Versioning?

Versioning in Amazon S3 is a feature that allows you to keep multiple variants of an object in the same bucket. With versioning enabled, you can preserve, retrieve, and restore every version of every object stored in your bucket, providing an additional layer of data protection against accidental deletion or modification.

Key Benefits of Versioning

  • Data Protection: Protects against accidental overwrites and deletions
  • Change Tracking: Maintain a complete history of object modifications
  • Easy Recovery: Quickly restore previous versions when needed
  • Compliance: Meet regulatory requirements for data retention
  • Collaboration: Multiple users can work on the same objects safely

How Versioning Works

When versioning is enabled on a bucket:

  • Each object gets a unique version ID
  • New uploads create new versions rather than overwriting existing objects
  • Previous versions remain accessible and can be retrieved at any time
  • Delete operations create a “delete marker” rather than permanently removing the object

Versioning States

S3 buckets can be in one of three versioning states:

  • Unversioned (default): No versioning, objects can be overwritten
  • Versioning-enabled: New versions are created for each upload
  • Versioning-suspended: No new versions created, but existing versions remain

Best Practices

  • Use Lifecycle Policies: Automatically delete old versions after a specified time
  • Monitor Costs: Versioning can significantly increase storage costs
  • MFA Delete: Enable MFA Delete for additional security on version deletion
  • Cross-Region Replication: Replicate versions across regions for disaster recovery

Static website

1. Enable versioning feature for bucket

  • In the S3 bucket interface, select your bucket name.

  • Select Properties, then under the Bucket Versioning section, select Edit.

    Static website

  • In the Bucket Versioning section, select Enable and Save changes.

    Static website

2. Change the content of the index.html file

  • Open the folder containing the files downloaded from step 2.2.

  • Select the index.html file, right-click, and select Open with > Notepad (or Edit in Notepad).

    Static website

  • Change the content AWS First Cloud AI Journey to HỌC CLOUD AI VUI BIẾT BAO <3 inside the body tag.

  • Save the changes using the key combination Ctrl + S.

    Before editing:

    Static website

    After editing:

    Static website

3. Check versioning feature on S3

  • Access the S3 bucket interface AWS First Cloud AI Journey, select Upload.

  • Drag and drop the edited index.html file into the bucket.

    Static website

  • Complete the upload process, then select Close.

    Static website

  • Search for index.html, then toggle Show versions to see the versions of the file.

    Static website

  • You will see two versions of the index.html file with different modification times.

    Static website

4. Test versioning feature on Cloudfront

  • Access 7.3 Check Amazon CloudFront and view the Distribution domain name.

    Static website

  • See whether the Default root object changes after uploading the new version of index.html or not.

  • Access Amazon CloudFront at https://console.aws.amazon.com/cloudfront/home, select the current Distribution ID.

    Static website

  • Select Behaviors, then select Edit.

    Static website

  • Under Cache key and origin requests, in the Cache policy section, select CachingDisabled. Then select Save changes.

    Static website

  • Wait until the status changes from Deploying to the last modified time.

    Static website

    Static website

  • Copy the Domain name into the browser to see the changes.

    Static website

  • To quickly restore the old content, delete the latest version of the index.html object in the S3 bucket.

    Static website

  • Select the object to delete and click Delete.

    Static website

  • Check and confirm the deletion by entering permanently delete and selecting Delete objects.

    Static website

  • Refresh the browser running the CloudFront Domain name to see the old content restored.

    Static website