Cloud storage bills grow quietly. Logs, backups, and user uploads accumulate in the most expensive storage class forever, because nobody remembers to move or delete them. Cloud Storage lifecycle rules fix that on Google Cloud: you declare once what should happen to objects as they age, and the service moves them to cheaper classes or deletes them automatically. In this guide you will write lifecycle rules that cut costs without deleting data anyone still needs.
The core idea is matching storage cost to access frequency. Data accessed daily belongs in Standard storage; data accessed monthly belongs in Nearline or Coldline; data kept only for compliance belongs in Archive. Lifecycle rules automate those transitions on a schedule, so your bill reflects how data is actually used instead of how it was first uploaded.

How Cloud Storage Lifecycle Rules Work
A lifecycle configuration is a list of rules attached to a bucket. Each rule has a condition, such as object age or storage class, and an action, such as changing the storage class or deleting the object. Google Cloud evaluates rules once a day, and an object that matches a condition is acted on within 24 hours. Rules never affect the current version of an object unless you explicitly include version conditions, which protects live data from an over-broad rule.
The available actions cover the common cases: SetStorageClass moves an object to Nearline, Coldline, or Archive; Delete removes it, including noncurrent versions and incomplete multipart uploads with the right conditions; and AbortIncompleteMultipartUpload cleans up failed uploads that would otherwise sit there costing money forever.
Prerequisites
- A Google Cloud project with billing enabled and a Cloud Storage bucket you own.
- Google Cloud CLI (gcloud) installed and authenticated.
- Basic familiarity with storage classes and object versioning.
Step 1: Design a Cloud Storage Lifecycle Policy
Before writing JSON, decide the policy on paper. A typical pattern for application logs is: keep 30 days in Standard, move to Nearline for 90 days, move to Coldline for a year, then delete. For backups, keep the latest versions in Standard and delete noncurrent versions after 30 days. Write the retention requirement down first, because a lifecycle rule is easy to deploy and embarrassing to explain after it deletes the wrong quarter of data.
Step 2: Apply Lifecycle Rules with gcloud
Save the policy as JSON and apply it to the bucket:
{
"rule": [
{
"action": {"type": "SetStorageClass", "storageClass": "NEARLINE"},
"condition": {"age": 30, "matchesStorageClass": ["STANDARD"]}
},
{
"action": {"type": "SetStorageClass", "storageClass": "COLDLINE"},
"condition": {"age": 120, "matchesStorageClass": ["NEARLINE"]}
},
{
"action": {"type": "Delete"},
"condition": {"age": 365}
}
]
}
gcloud storage buckets update gs://my-app-bucket --lifecycle-file=lifecycle.json
gcloud storage buckets describe gs://my-app-bucket --format="default(lifecycle)"
The second command confirms the rules are live. Always verify after applying: a typo in the bucket name applies the policy to the wrong bucket, and a missing condition can match far more objects than intended.
Step 3: Protect Versions and Test Safely
If versioning is enabled, add a separate rule for noncurrent versions so old versions do not accumulate silently:
{
"action": {"type": "Delete"},
"condition": {"isLive": false, "numNewerVersions": 3}
}
This keeps the three newest versions of each object and deletes older ones. Test every new policy on a copy of the bucket first, or start with a SetStorageClass rule only and add deletion after a month of observing that the transitions behave as expected. For data under legal hold or retention policy, lifecycle deletion is blocked by the bucket lock, which is the safety net you want.
Finally, review the policy once a quarter. Access patterns change: a dataset nobody reads for a year may suddenly become hot again, and a rule that was saving money can start costing retrieval fees. A short quarterly review of the storage breakdown by class in the Cloud console keeps the policy matched to reality.
Troubleshooting Cloud Storage Lifecycle Rules
Objects never transition. Check that the condition matches: matchesStorageClass must list the object’s current class, and age counts from creation, not from last access. Also allow 24 hours after applying the rule.
Too many objects deleted. A rule without isLive or prefix conditions applies bucket-wide. Restore from versioning if enabled, otherwise from your backup, then re-scope the rule with matchesPrefix.
Costs went up, not down. Moving objects to Archive and then reading them incurs retrieval fees, and early deletion of Nearline or Coldline objects incurs a minimum-storage charge. Lifecycle rules save money only when the access pattern matches the class.
Rule changes do not appear. Re-run the describe command and confirm you updated the right project and bucket; gcloud defaults can silently point at a different project.
Conclusion
A well-designed Cloud Storage lifecycle policy turns storage cost management from a quarterly cleanup chore into a standing rule: hot data stays fast, cold data gets cheap, and obsolete data disappears on schedule. Design the policy before writing it, test on a copy, and protect versions explicitly. For more Google Cloud practice, see our guides on Google Cloud Storage signed URLs and Google Cloud Pub/Sub messages. The official reference is Cloud Storage lifecycle documentation.