0
0
GCPcloud~30 mins

Lifecycle management rules in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
GCP Storage Bucket Lifecycle Management Rules
📖 Scenario: You are managing a Google Cloud Storage bucket that stores logs and backups. To save costs and keep the bucket organized, you want to automatically delete old files and move some files to cheaper storage classes after a certain time.
🎯 Goal: Create a lifecycle management rule for a GCP Storage bucket that deletes objects older than 30 days and changes the storage class to Nearline for objects older than 7 days.
📋 What You'll Learn
Create a dictionary called lifecycle_rule with a rule to delete objects older than 30 days
Add a second rule to change storage class to NEARLINE for objects older than 7 days
Combine these rules into a lifecycle configuration dictionary called lifecycle_config
Add the lifecycle configuration to a bucket configuration dictionary called bucket_config
💡 Why This Matters
🌍 Real World
Lifecycle management rules help automate storage cost savings and data retention policies by automatically deleting or moving files based on age or other conditions.
💼 Career
Cloud engineers and administrators use lifecycle rules to optimize storage costs and maintain compliance with data retention requirements.
Progress0 / 4 steps
1
Create the first lifecycle rule to delete old objects
Create a dictionary called lifecycle_rule with a key action set to {'type': 'Delete'} and a key condition set to {'age': 30} to delete objects older than 30 days.
GCP
Need a hint?

Use a dictionary with keys action and condition. The action type should be Delete. The condition should specify age as 30.

2
Create the second lifecycle rule to change storage class to NEARLINE
Create a dictionary called storage_class_rule with action set to {'type': 'SetStorageClass', 'storageClass': 'NEARLINE'} and condition set to {'age': 7} to change storage class for objects older than 7 days.
GCP
Need a hint?

Use a dictionary with action key having type as SetStorageClass and storageClass as NEARLINE. The condition should have age 7.

3
Combine both rules into a lifecycle configuration
Create a dictionary called lifecycle_config with a key rule set to a list containing lifecycle_rule and storage_class_rule.
GCP
Need a hint?

Put both rules inside a list assigned to the rule key in lifecycle_config.

4
Add lifecycle configuration to the bucket configuration
Create a dictionary called bucket_config with a key lifecycle set to lifecycle_config.
GCP
Need a hint?

Assign lifecycle_config to the lifecycle key in bucket_config.