AcloudA

How to Add Lifecycle Rule for a Cloud Storage Bucket

Posted by Karim Buzdar on June 2, 2020

Google Cloud Storage is unified object storage provided by the Google Cloud Platform (GCP). It allows low cost and almost unlimited storage space with several features that make it a highly popular service. Understanding how to properly use and configure the different features you use can make a significant difference, both in terms of daily operations and overall cost. The Lifecycle management feature in Google Cloud storage makes this task easier. This feature is not limited to just Google Cloud storage, other Cloud storage solutions also offer similar lifecycle management services.

With lifecycle management services, rules can be added to automatically delete or move the data to another storage class. These rules can be added based on various factors such as age, creation date, storage class, versions, and state. These rules are useful when you want to control the way data live in the storage bucket. An example of this would be to automatically move the data to a cheaper storage class such as Nearline 60 days after creation and then move it to Coldline storage class after another 60 days. This way, you can not only reduce the cost but also the reduce time spent on managing the data. To manage the lifecycle rules, you can use the Google Cloud Console, Gsutil CLI, SDK or API.

In this article, we will explain How to Add Lifecycle Rule for a Cloud Storage Bucket to automate certain operations on your data and reduce the overall cost. We will explain the procedure by adding the two rules that will:

  • Automatically delete the data
  • Automatically change the storage class.

Note that we will be using the Google Cloud Console for adding the life cycle rules.

Adding Lifecycle Rule using Google Cloud Console

As the lifecycle rules are applied to a bucket, so the first step would be to create a bucket. If you have already created a bucket, then you can proceed with the following procedure:

Adding a Lifecycle Rule for Automatically Deleting Data

In the following procedure, we will explain how to add a rule that automatically deletes data if the specified conditions are met. As an example, we will create a rule by which any object older than 10 days will be automatically deleted.

1. Open the following link to navigate to the GCP Browser.

https://console.cloud.google.com/storage/browser

2. Select the project where you have created the bucket by using the drop-down arrow at the top bar.

3. In the Storage browser window, you will see different columns against each bucket. Click None under the Lifecycle rules column for your desired bucket as follows:

Lifecycle rules

4. Next, in the following window, click the Add rule button to add the lifecycle rule. Note that the rule you add will be applied to all objects in a bucket.

Add the lifecycle rule

5. Select the conditions for the object. Action will be triggered if the specified conditions are met. You can choose from the following conditions set:

  • Age: Enter number of days (after the creation date) the data has resided in the bucket
  • Creation date: When the object is created before or at the specified date.
  • Storage class: Specify the storage class for the objects.
  • Newer versions: Refers to the number of version the data has.
  • Live state: Select either Noncurrent or Live option.

In our example, we have specified 10 days for age. Once you have selected the required condition, click CONTINUE button.

Select the conditions for the object

6. Next, select the required action to be taken if the above conditions are met. As we are going to set a rule to automatically delete the data if the conditions are met. So choose the Delete option and click Continue.

Then click the Save button in order to save the rule.

Select the required action

Adding a Lifecycle Rule for Automatically Changing the Storage Class

In the following procedure, we will see how to add a rule that automatically changes the storage class if the specified conditions are met. Changing the storage class of older and less commonly accessed data can greatly reduce the storage costs. As an example, we will create a rule by which any object older than 10 days residing in Standard storage class will be automatically moved to Nearline storage class.

1. Open the following link to navigate to the GCP Browser.

https://console.cloud.google.com/storage/browser

2. Select the project where you have created the bucket by using the drop-down arrow at the top bar.

3. In the Storage browser window, you will see different columns against each bucket. Click the None under the Lifecycle rules column for your desired bucket. Note that, if you have already created a rule (like in our case), you will see it listed under the Lifecycle rules instead of None as shown below:

Storage browser window

4. Now in the following view, click the Add rule button in order to add the lifecycle rule. Note that the added rule will be applied to all objects in a bucket.

Add rule

5. Select the conditions for the object. Action will be triggered if the specified conditions are met. You can choose from the different conditions set (explained in the previous section).

 Select the conditions for the object

6. Next, select the required action to be taken if the above conditions are met. As we are going to set a rule to automatically change the storage class if the specified conditions are met. So choose either of the following options and click Continue.

  • Set to Nearline
  • Set to Coldline
  • Set to Archive

Now click the Save button in order to save the rule.

Object lifestyle rule

That is all there is to it! In this article, we have explained how to add lifecycle rules for a Cloud Storage Bucket. These lifecycle rules can help you in automating certain operations on the data as well as reducing the cost of data storage in Google Cloud.

Related materials:

Views All Time
2
Views Today
5
Return to all posts

Update your Azure DNS automatically when you have a dynamic public IP
Azure Policy Overview