Google Cloud Storage & Life Cycle Management

Nilesh Khandalkar
2 min readAug 8, 2023

--

This article gives a glimpse of Google Cloud Storage Life Cycle Management for Google Cloud Storage.

Cloud Storage is a storage service for storing and accessing data on Google Cloud Platform. There is no limit for storage and its entirely scalable. It gives storage options like Standard [frequently accessed data], Nearline [Infrequent access data around 30 days — low cost option], Coldline [Infrequent access data around 90 days — very low cost option], Archival storage [mainly for backup and data can be around 365 days, lowest cost] and depending of business case you can opt any of these options.

Object Life Cycle Management gives an option to set Time to Live for objects, retaining non-current objects or to downgrade the storage options to manage cost, the LCM is set on GCS bucket and the configuration gets apply to current and future objects in the GCS bucket.

Each Life Cycle Management contains set of rules which can have one or more conditions, the action is taken on an object when that object matches the conditions in any of the rules. The Life Cycle rule can take upto 24 hours to get into effect but I have observed that it takes couple of hours for PB of data.

The main two life cycle actions are Delete and SetStorageClass. The Delete action deletes an object when the object meets all conditions specified in the lifecycle rule. For e.g Delete objects created before August 1st 2023.

The SetStorageClass action changes the storage class of an object. The Life Cycle rule includes conditions which the object must meet before the action defined in the rule occurs in the object.

Life Cycle Actions

The Life Cycle rules can be set via Google Cloud console, Command line [gcloud,gsutil] , Client libraries [python, Java, etc], Terraform , or Rest API’s [JSON, XML]

Sample Python code to set Life Cycle rule on a bucket

The GCS bucket needs to be explicitly deleted once life cycle rules removes the objects from the GCS bucket.

https://cloud.google.com/storage#options

https://cloud.google.com/storage/docs/lifecycle

https://cloud.google.com/storage/docs/managing-lifecycles#set

--

--

Nilesh Khandalkar

Passionate about Data and Cloud, working as Data Engineering Manager at Capgemini UK. GCP Professional Data Engineering Certified Airflow Fundamentals Certified