Setting Cloud Storage Lifecycle Rules

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

While saving an object in a Cloud Storage bucket is relatively inexpensive, there is, nonetheless, a cost. The cost varies depending on the storage class selected. Certain objects are required to be more available at first, requiring the storage class with the highest availability and cost. Such objects may eventually be relegated to less available and less expensive storage classes and, even, be deleted. Management of these objects over time can be handled automatically by establishing and implementing lifecycle rules. In this hands-on lab, we’ll set a variety of lifecycle rules for Google Cloud Storage buckets both from the console and the command line.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Cloud Storage Bucket
  1. From the Google Cloud console, navigate to Cloud Storage > Browser.
  3. Under Name your bucket, enter a globally unique name.
  4. Click Create.
Define the First Lifecycle Rule
  1. Under Bucket details, select LIFECYCLE.
  2. In Rules, click Add a rule.
  3. Under Select an action, select Set storage class to Nearline.
  4. Click Continue.
  5. Under Select object conditions, select Age and enter 180.
  6. Click Continue.
  7. Click Create.
Define the Second Lifecycle Rule
  1. In Rules, click Add a rule.
  2. Under Select an action, select Set storage class to Coldline.
  3. Click Continue.
  4. Under Select object conditions, select Age and enter 365.
  5. Click Continue.
  6. Click Create.
Get Lifecycle Rules from the Command Line
  1. At the top menu, click the Cloud Shell icon (>_) to activate Cloud Shell.

  2. In the Cloud Shell, enter the following code:

    gsutil lifecycle get gs://<BUCKETNAME>
  3. Review output.

Set the Lifecycle Rule with the JSON File
  1. Clone a repo and change to the lab’s directory:

    git clone
    cd content-gc-essentials/cloud-storage-lifecycle-lab
  2. Review the file in Cloud Editor.

  3. In Cloud Shell, enter the following code:

    gsutil lifecycle set delete-after-two-years.json gs://<BUCKET_NAME>
  4. Confirm the lifecycle rule has been added in the console.

Additional Resources

Your entire company is looking for ways to lower expenses, and you’ve been asked to set up a series of Cloud Storage lifecycle rules for a particular bucket. The bucket should be configured to move the objects within it from a Standard storage class to Nearline after six months. After a year, the objects should be moved to Coldline. After two years, the objects should be set for deletion. You decide to use both the console and the command line to achieve these goals.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?