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.
- From the Google Cloud console main navigation, choose Cloud Storage.
- Click Create bucket.
- Name the bucket uniquely and click Continue
- In the Location Type section, select Region and click Continue.
- Click Create.
- Define first lifecycle rule.
- From the Cloud Storage browser page, click None in the Lifecycle column for the bucket just created.
- Click Add rule.
- Under Select object conditions, set the following:
- Age: 180
- Storage class: Regional, Standard
- Click Continue.
- Under Select action, choose Set to Nearline.
- Click Continue.
- Click Save.
- Define second lifecycle rule.
- From the Cloud Storage browser page, click Enabled in the Lifecycle column.
- Click Add rule.
- Under Select object conditions, set the following:
- Age: 365
- Storage class: Nearline
- Click Continue.
- Under Select action, choose Set to Coldline.
- Click Continue.
- Click Save.
- From command line, get lifecycle rules.
Click Activate Cloud Shell.
In the Cloud Shell, enter the following code:
gsutil lifecycle get gs://[BUCKETNAME]
Review output.
- Set lifecycle rule with JSON file.
Clone a repo and change to the lab’s directory:
git clone https://github.com/linuxacademy/content-gc-essentials cd content-gc-essentials/cloud-storage-lifecycle-lab
Review file in editor.
In the Cloud Shell, enter the following code:
gsutil lifecycle set delete-after-two-years.json gs://[BUCKET_NAME]
Confirm the lifecycle rule has been added in the console.