Amazon S3 Versioning and Lifecycle Policies

Hands-On Lab

 

Photo of Christophe Limpalair

Christophe Limpalair

VP of Growth in Marketing

Length

00:45:00

Difficulty

Beginner

AWS' S3 service is one of the most used, if not the most used, service AWS has to offer. It is typically very inexpensive storage but, once you start to scale, it can become extremely expensive. AWS provides several classes of S3 storage that can help manage costs based on retrieval and durability requirements of your data. Utilizing S3 Lifecycle polices can help ensure your data is stored at the best possible cost based on your requirements. This lab will cover how to manage those policies based on the requirements of your organization.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Introduction

This lab will introduce versioning and lifecycle policies for Amazon S3 buckets. The environment has already been prepared with two buckets in S3 that we can use to enable versioning and create the following example lifecycle rules:

For the tmpfiles bucket:

  • Whole Bucket: Delete all versions after 5 days.

For the s3bucket bucket:

  • documents: Transition to Standard - Infrequent Access after 90 days.
  • Whole Bucket:
    • Transition previous versions to Standard - Infrequent Access after 30 days.
    • Archive previous versions after 60 days.

This written guide focuses on the steps to complete the lab. It is recommended that you watch the accompanying lab video for more details.

Enable Versioning

Navigate to the S3 Management Console in AWS. Enable versioning:

  • Click the title of the bucket with s3bucket in its name and click the Properties tab.
  • Click the Versioning section and select the Enable Versioning option.

Repeat these steps to enable Versioning on the tmpfiles bucket.

Create Lifecycle Rules

Navigate to the Management tab and ensure the Lifecycle section is highlighted. Use the Add lifecycle rule button to begin adding lifecycle rules to match those outlined in the Introduction.

For the s3bucket bucket:

documents lifecycle:

We will set up a rule that transitions files inside of any "document" folders within the bucket to the Standard - Infrequent Access Storage Class 30 days after the object's creation.

  • Click the Add lifecycle rule button if you haven't already.
  • Give the rule an appropriate name, like documents-infreq-access.
  • For the filter setting, type a prefix of documents (this will apply the rule to any folders or objects who's names start with "documents"). Click the Next button.
  • Check the option to configure transition for the Current version.
  • Click the + Add Transition link and set it to Transition to Standard-IA after 90 days.
  • Click the Next buttons. Notice the options here, but leave them unchanged. Again, click the Next button.
  • Ensure the desired setting of 90 days after the object's creation date has been set. (Transition to Standard-IA after 90 days)
  • Review the other information, then click the Save button.

Whole bucket lifecycle

Next, we will create a rule that applies to the entire bucket that archives previous versions of objects after 5 days and delete them after 10.

  • Click Add lifecycle rule and set the Rule Name to something appropriate: archive-versions
  • If no filter is defined, the rule will apply to the whole bucket. Leave the filter settings empty and click the Next button.
  • Check the Previous versions option for the transition.
  • Click the + Add transition link and select a Transition to Standard-IA after 30 days.
  • Add another transition, this time for Transition to Amazon Glacier after 60 days.
  • Click the Next button. Leave these settings alone and click Next again.
  • Verify the settings and notice the warning. We see this because the rules we just configure apply to everything, including the documents preset from our previous rules.
  • Click the Save button.

For the tmpfiles bucket:

Finally, we will set up a rule that permanently deletes objects in tmpfiles bucket. Since Versioning is enabled for this bucket, we first need to instruct the current version of the objects to Expire in addition to Permanently Deleting previous versions.

Navigate to the Lifecycle settings for the tmpfiles bucket.

  • Click Add lifecycle rule. Leave the filter setting empty so the rule applies to the entire bucket. Give it a fitting name of tmp-delete. Click Next.
  • Since we aren't transitioning the objects between storage classes, leave these settings unchanged and click Next.
  • We want to set the Current version and Previous versions to expire, so check both of those options under Configured expiration.
  • Configure the settings to Expire current version of object after 5 days.
  • Similarly, set it to Permanently delete previous versions after 5 days from becoming a previous version.
  • Click the Next button.
  • Verify the settings are correct and click the Save button.

Storage Classes

The AWS Documentation offers descriptions of the different storage classes. Read through the differences and consider the pricing of each one to build lifecyle rules that suit your needs. A proper lifecycle configuration works for you to reduce storage costs.