This chapter covers Cloud Storage Lifecycle Rules, a key feature for automatically managing object storage costs and compliance. For the ACE exam, lifecycle rules appear in approximately 5-8% of questions, often integrated with cost optimization scenarios. You will learn how to define rules that transition objects between storage classes or delete them based on conditions like age, creation date, or storage class. Mastering this topic is essential for designing cost-effective storage solutions and passing the exam.
Jump to a section
Imagine you manage a massive warehouse with millions of items arriving daily. You have three main storage zones: a 'hot zone' near the loading dock for frequently accessed items (costlier per square foot but fast retrieval), a 'cool zone' further away for items accessed monthly (moderate cost, slower retrieval), and a 'cold archive' in the basement for items rarely touched (cheapest but retrieval takes hours). Additionally, you have a shredder for items that have expired. Your warehouse manager (the lifecycle rule) is a set of automated instructions: 'If an item hasn't been picked in 30 days, move it from hot to cool. If it hasn't been picked in 365 days, move it to archive. If it's been in archive for 10 years, shred it.' The manager checks each item's 'last access date' tag daily. Crucially, the move is not instant — it is scheduled as a batch job every 24 hours. Items moved to archive must first be stored for at least 30 days in cool before archiving (a constraint). If you misconfigure the rule (e.g., set the cool-to-archive move at 30 days instead of 365), you risk expensive retrieval costs when an item is needed quickly. This mirrors Cloud Storage lifecycle management: you define rules that transition objects between storage classes (Standard, Nearline, Coldline, Archive) or delete them, based on age or other conditions. The rules are evaluated asynchronously, typically within 24 hours. There are constraints: objects must be in a storage class for a minimum period (e.g., 30 days for Nearline) before transitioning to a colder class, and lifecycle actions are billed for each operation. Just as the warehouse manager cannot move items that are already in the shredder, you cannot apply lifecycle rules to objects in the Archive class to move them to a colder class — you can only delete them. Understanding these mechanics is key to passing the ACE exam.
What Are Cloud Storage Lifecycle Rules?
Cloud Storage Lifecycle Rules are automated policies that manage the lifecycle of objects in Google Cloud Storage (GCS) buckets. They allow you to automatically transition objects to lower-cost storage classes (e.g., from Standard to Nearline, Coldline, or Archive) or delete them when they meet certain conditions. This helps reduce storage costs and enforce data retention policies without manual intervention.
Why They Exist
In enterprise environments, data accumulates rapidly. Many objects become less frequently accessed over time but still need to be retained for compliance or future analysis. Manually moving or deleting objects is impractical at scale. Lifecycle rules automate this process, ensuring that data is stored in the most cost-effective class based on its access patterns and age. The ACE exam tests your ability to configure these rules correctly, especially regarding conditions and actions.
How Lifecycle Rules Work Internally
Lifecycle rules are defined at the bucket level. Each rule consists of a condition and an action. The condition specifies when the action should be triggered, such as after a certain number of days from object creation, or when the object's storage class is a specific class. The action defines what happens: either transitioning the object to another storage class or deleting it.
When you set a lifecycle rule, GCS evaluates it asynchronously. There is no guarantee of immediate execution; actions typically occur within 24 hours, but can take up to 48 hours in some cases. The evaluation is done on a best-effort basis. Objects that match the conditions are queued for the action. For transition actions, the object is moved to the target storage class. For delete actions, the object is permanently removed.
Key Components and Defaults
- Conditions:
- age: Number of days from object creation to trigger action. Default: no value (required for age-based rules).
- createdBefore: Date (e.g., '2023-01-01') – triggers action for objects created before that date.
- isLive: Boolean (true/false) – applies to live or noncurrent (versioned) objects. Default: true.
- matchesStorageClass: List of storage classes (e.g., 'STANDARD', 'NEARLINE', 'COLDLINE', 'ARCHIVE') – triggers action only for objects in those classes.
- numNewerVersions: Number of newer versions of an object (for versioned buckets).
- daysSinceNoncurrentTime: Days since object became noncurrent (versioned buckets).
- daysSinceCustomTime: Days since custom time was set on object.
- customTimeBefore: Date before which custom time was set.
- noncurrentTimeBefore: Date before which object became noncurrent.
- Actions:
- SetStorageClass: Transition to 'NEARLINE', 'COLDLINE', 'ARCHIVE', or 'STANDARD'.
- Delete: Permanently delete the object.
- AbortIncompleteMultipartUpload: Abort incomplete uploads after a specified number of days.
- Defaults: - No default rules exist; you must explicitly set them. - Lifecycle rules are evaluated approximately once per day. - Minimum storage duration before transitioning: 30 days for Nearline, 90 days for Coldline, 365 days for Archive. If you attempt to transition before the minimum, the transition will be delayed until the minimum period is met. - There is no cost for setting lifecycle rules, but each transition action incurs a charge (Class A operation for transition to a colder class, Class B for transition to a warmer class). Deletion is also a Class A operation.
Configuration and Verification
Lifecycle rules can be configured via the Google Cloud Console, gsutil, or REST API.
Using gsutil:
To set a lifecycle rule from a JSON file:
gsutil lifecycle set lifecycle-config.json gs://my-bucketExample JSON file:
{
"rule": [
{
"action": {"type": "SetStorageClass", "storageClass": "NEARLINE"},
"condition": {"age": 30, "isLive": true}
},
{
"action": {"type": "Delete"},
"condition": {"age": 365, "isLive": true}
}
]
}To view current lifecycle configuration:
gsutil lifecycle get gs://my-bucketUsing Console:
Navigate to Cloud Storage > Buckets > Select bucket > Edit lifecycle rules.
Add rules by specifying condition and action.
Interaction with Related Technologies
Object Versioning: Lifecycle rules can target live and noncurrent objects separately. For example, you can delete noncurrent versions after 30 days while keeping live versions.
Retention Policies: Lifecycle rules cannot delete objects that are under a retention policy (e.g., retention lock). The retention policy takes precedence.
Bucket Lock: If a bucket has a retention policy with retention lock enabled, lifecycle delete actions will fail for objects within the retention period.
Requester Pays: Lifecycle actions are performed by the bucket owner, regardless of requester pays setting.
Object holds: Lifecycle rules do not respect event-based holds or temporary holds; those are independent features.
Important Exam Details
Lifecycle rules are evaluated asynchronously; do not expect immediate execution.
Transition actions are subject to minimum storage durations. Attempting to transition earlier will cause the action to be delayed until the minimum is met.
You cannot transition objects from Archive to a colder class; Archive is the coldest class. You can only delete from Archive.
Lifecycle rules can have multiple rules, and they are evaluated in order. However, the order does not guarantee precedence; all matching rules may apply, but only one action per object per day. If multiple rules match, the most specific action may apply, but it's best to avoid overlapping conditions.
The age condition uses the object's creation time (not last modification time).
For versioned buckets, isLive distinguishes between current (live) and noncurrent versions.
The numNewerVersions condition is useful for cleaning up old versions.
The daysSinceNoncurrentTime condition triggers after an object becomes noncurrent for a specified number of days.
Lifecycle rules can also abort incomplete multipart uploads after a specified number of days, which is helpful for cleaning up partial uploads.
Common Pitfalls
Using age with createdBefore incorrectly: age is relative to creation, createdBefore is an absolute date. They can be combined, but ensure logic is correct.
Forgetting that transition to colder class has minimum storage duration: objects moved to Nearline must stay 30 days before moving to Coldline, etc.
Assuming lifecycle rules run instantly: they run daily, so plan accordingly.
Overlapping rules may cause unintended deletions or transitions. Always test with a small set of objects.
Verification Commands
To check if lifecycle rules are working, you can use gsutil ls -L to see the storage class of objects over time. Also, audit logs (Cloud Audit Logs) record lifecycle actions for monitoring.
Example:
gsutil ls -L gs://my-bucket/object.txt | grep "Storage class"This shows the current storage class, which should change after a lifecycle transition.
Define Lifecycle Rule Conditions
Identify the conditions under which objects should be transitioned or deleted. Common conditions include age (days since creation), creation date before a specific date, storage class, or version status. For example, a condition might specify 'age >= 30' and 'storage class = STANDARD'. The condition must be precise to avoid unintended actions. In the ACE exam, you may be asked to select the correct condition for a given scenario, such as moving objects older than 90 days to Coldline. Note that age is calculated from the object's creation time, not last access time. Also, you can combine multiple conditions in a single rule using AND logic (all must be true).
Select Action: Transition or Delete
Choose the action to perform: SetStorageClass (transition to a different class) or Delete (permanent removal). For transitions, specify the target storage class (e.g., NEARLINE, COLDLINE, ARCHIVE). Deleting is irreversible. The exam often tests that you cannot transition from Archive to a colder class because Archive is the coldest. Also, note that transitioning to a warmer class (e.g., from Coldline to Standard) is allowed but incurs costs. Deleting is a Class A operation. Actions are executed asynchronously, usually within 24 hours.
Create Lifecycle Configuration File
Write the lifecycle rules in JSON format. The JSON structure includes a 'rule' array with objects containing 'action' and 'condition'. For example: {"action": {"type": "SetStorageClass", "storageClass": "NEARLINE"}, "condition": {"age": 30}}. You can have multiple rules. The order of rules does not affect execution; GCS evaluates all rules and applies the first matching action per object per day. Ensure the JSON is valid. Use gsutil lifecycle set to apply the configuration to a bucket. The exam may ask you to identify a correct JSON snippet from multiple choices.
Apply Lifecycle Rule to Bucket
Use the gcloud storage buckets update command or gsutil lifecycle set to apply the JSON configuration to a specific bucket. For example: gsutil lifecycle set config.json gs://my-bucket. This overwrites any existing lifecycle rules. You can also use the Cloud Console to add rules through a GUI. After applying, verify with gsutil lifecycle get gs://my-bucket. The ACE exam expects you to know the correct gsutil commands. Note that you cannot apply lifecycle rules at the project level; they are always per bucket.
Verify Lifecycle Rule Execution
Monitor the bucket to ensure rules are working. Since execution is asynchronous, check after at least 24 hours. Use gsutil ls -L to inspect object storage classes. For example, if a rule moves objects to Nearline after 30 days, after 31 days the storage class should change. Also, review Cloud Audit Logs for lifecycle actions (e.g., storage.googleapis.com/object_transition). The exam may ask about troubleshooting when rules don't execute as expected. Common issues: minimum storage duration not met, retention policy blocking deletion, or incorrect conditions. Always verify with logs.
Enterprise Scenario 1: Cost Optimization for Log Data
A large e-commerce company generates terabytes of server logs daily. They need to retain logs for 90 days for debugging, then for 7 years for compliance. Initially, logs are stored in Standard class for fast access. After 30 days, access frequency drops significantly. They configure a lifecycle rule to transition logs from Standard to Nearline after 30 days, then from Nearline to Coldline after 90 days, and finally delete after 7 years. This reduces storage costs by ~70%. In production, they use versioning to keep multiple log versions and add a rule to delete noncurrent versions after 30 days. A common misconfiguration is setting the transition to Coldline at 30 days, which violates the 90-day minimum for Coldline, causing the rule to be delayed. The team monitors using Cloud Monitoring alerts on lifecycle action failures.
Enterprise Scenario 2: Backup Data Archival
A financial institution backs up databases daily and stores backups in Standard class. After 1 year, backups are rarely needed but must be retained for 10 years. They implement a lifecycle rule to transition backups older than 365 days to Archive class. They also set a rule to delete backups older than 10 years. Because Archive has a 365-day minimum, they ensure backups stay in Standard for at least 365 days before transitioning. A pitfall: they initially set the transition to Archive at 180 days, but GCS delayed the action until day 365. After correcting, they saved costs. They also use bucket lock to prevent deletion of backups during the retention period, which overrides lifecycle delete actions.
Enterprise Scenario 3: Media Content Lifecycle
A media streaming service stores video files. New releases are in Standard for fast streaming. After 6 months, they become less popular. They transition to Nearline after 180 days, then to Coldline after 2 years, and delete after 5 years. They also abort incomplete multipart uploads after 7 days to clean up failed uploads. A challenge: the lifecycle rule for aborting incomplete uploads must have a condition with age or daysSinceCustomTime? Actually, for incomplete uploads, the condition uses age based on the upload initiation time. They set age: 7 and action AbortIncompleteMultipartUpload. This works well. They also use numNewerVersions to keep only the latest 3 versions of each video. The ACE exam often tests these real-world patterns.
Exactly What ACE Tests
ACE exam objective 2.2 (Planning Solutions) includes lifecycle rules under 'Storage'. Expect 2-3 questions that test your ability to:
Select the correct condition (age, createdBefore, matchesStorageClass, isLive) for a given business requirement.
Identify the appropriate action (SetStorageClass vs Delete) and target storage class.
Understand constraints: minimum storage durations (30d Nearline, 90d Coldline, 365d Archive).
Recognize that lifecycle rules are asynchronous and evaluated daily.
Know that you cannot transition from Archive to a colder class.
Differentiate between conditions for live and noncurrent objects.
Interpret JSON lifecycle configuration snippets.
Common Wrong Answers and Why
Choosing 'createdBefore' instead of 'age': Candidates often confuse absolute date with relative age. Example: 'Move objects older than 30 days' requires age: 30, not createdBefore: '2023-01-01'. The exam will present scenarios with 'older than X days' – always use age.
Assuming immediate execution: Many think lifecycle actions happen instantly. The exam may ask 'How long after setting a rule will objects be deleted?' The correct answer is 'within 24 hours', not immediately.
Transitioning from Archive to a colder class: Archive is the coldest; you cannot transition to a colder class. Some candidates try to select a transition action from Archive, but only Delete is allowed.
Ignoring minimum storage duration: For example, setting a rule to transition from Standard to Coldline after 30 days. The rule will be delayed until day 90 because Coldline requires 90-day minimum from the time the object was in Standard? Actually, the minimum is from when the object was created or last transitioned? The rule is that an object must be in a storage class for at least the minimum duration before transitioning to a colder class. So if you create an object in Standard and want to move to Coldline, you must wait 90 days from creation (if Standard has no minimum) but Coldline requires 90 days in that class? Wait: The minimum storage duration is for the target class. For example, if you transition an object to Nearline, it must stay in Nearline for 30 days before it can be transitioned to Coldline. But if you transition directly from Standard to Coldline, the object must have been in Standard for? Actually, the minimum duration is for the storage class you are moving into. So if you move to Coldline, the object must be at least 90 days old (since creation) because Coldline has a 90-day minimum. The exam may test this nuance.
Specific Numbers and Terms
Minimum ages: 30 days for Nearline, 90 days for Coldline, 365 days for Archive.
Default evaluation frequency: once per day (24 hours).
Actions: SetStorageClass, Delete, AbortIncompleteMultipartUpload.
Conditions: age, createdBefore, isLive, matchesStorageClass, numNewerVersions, daysSinceNoncurrentTime, customTimeBefore, noncurrentTimeBefore.
gsutil commands: gsutil lifecycle set, gsutil lifecycle get.
JSON structure: {"rule": [{"action": {...}, "condition": {...}}]}.
Edge Cases and Exceptions
Lifecycle rules cannot delete objects under a retention policy (including retention lock).
Objects with holds (event-based or temporary) can still be deleted by lifecycle if they meet conditions – holds do not block lifecycle.
For versioned buckets, deleting a live object creates a noncurrent version; lifecycle can delete noncurrent versions separately.
Lifecycle rules apply to objects in the bucket, not to the bucket itself.
If a rule has multiple conditions, all must be true (AND logic).
Rules can be overlapping; if two rules match, only one action is applied per day, but it's unpredictable which one, so avoid overlaps.
How to Eliminate Wrong Answers
If the question says 'transition to Archive after 1 year', the condition must use age: 365 (or age: 365 and isLive: true). Eliminate options with createdBefore or matchesStorageClass unless specified.
If the question mentions 'delete noncurrent versions after 30 days', look for isLive: false or numNewerVersions condition. Eliminate options using isLive: true.
If the question says 'abort incomplete uploads after 7 days', the action must be AbortIncompleteMultipartUpload. Eliminate Delete or SetStorageClass.
Pay attention to minimum storage durations: if a rule transitions to Coldline at 30 days, it's invalid because Coldline requires 90 days. The exam may have a distractor that says 'the rule will be applied after 90 days' – that is correct behavior, not an error.
Master these points to confidently answer lifecycle rule questions.
Lifecycle rules are defined per bucket using JSON configuration with conditions and actions.
Conditions include: age, createdBefore, isLive, matchesStorageClass, numNewerVersions, daysSinceNoncurrentTime, customTimeBefore, noncurrentTimeBefore.
Actions: SetStorageClass (transition) or Delete (permanent removal) or AbortIncompleteMultipartUpload.
Minimum storage durations: 30 days for Nearline, 90 days for Coldline, 365 days for Archive before transitioning to a colder class.
Lifecycle actions are asynchronous and typically execute within 24 hours.
Cannot transition from Archive to a colder class; only delete is allowed.
Retention policies override lifecycle delete actions.
gsutil commands: lifecycle set and lifecycle get.
For versioned buckets, use isLive and numNewerVersions to manage versions.
Lifecycle rules do not affect objects with holds (event-based or temporary).
These come up on the exam all the time. Here's how to tell them apart.
Lifecycle Rules with age condition
Relative time from object creation (e.g., 30 days).
Automatically applies to future objects as they age.
Syntax: "age": 30
Good for rolling retention policies.
Example: Delete logs older than 90 days.
Lifecycle Rules with createdBefore condition
Absolute date (e.g., before 2023-01-01).
Does not automatically apply to new objects after the date; only to objects created before that date.
Syntax: "createdBefore": "2023-01-01"
Good for one-time cleanup of old data.
Example: Delete all objects created before 2020.
Mistake
Lifecycle rules execute immediately after configuration.
Correct
Lifecycle rules are evaluated asynchronously, typically within 24 hours, but can take up to 48 hours. There is no immediate execution guarantee.
Mistake
You can transition objects from Archive to a colder storage class.
Correct
Archive is the coldest storage class. You cannot transition from Archive to any other class; only deletion is allowed from Archive.
Mistake
The 'age' condition uses the last modification time of the object.
Correct
The 'age' condition uses the object's creation time, not last modification time. For example, if an object is created on Jan 1, age 30 triggers on Jan 31 regardless of updates.
Mistake
Lifecycle rules can delete objects that are under a retention policy.
Correct
Retention policies, especially with retention lock, prevent deletion of objects until the retention period expires. Lifecycle rules cannot override retention policies.
Mistake
You can set lifecycle rules at the project level to apply to all buckets.
Correct
Lifecycle rules are defined per bucket, not at the project level. Each bucket must have its own lifecycle configuration.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
The minimum age is 90 days from object creation. If you set a lifecycle rule to transition to Coldline at age 30, the action will be delayed until the object is 90 days old. This is because Coldline has a 90-day minimum storage duration. On the ACE exam, remember that Nearline requires 30 days, Coldline 90 days, and Archive 365 days.
No, lifecycle rules cannot delete objects that are under a retention policy. Retention policies (especially with retention lock) prevent deletion until the retention period expires. If a lifecycle rule attempts to delete such an object, the action will fail. The exam may test this interaction.
You need to use a condition with `isLive: false` (or `numNewerVersions`). For example: {"action": {"type": "Delete"}, "condition": {"isLive": false, "age": 30}}. This will delete noncurrent versions that are 30 days old. Alternatively, you can use `numNewerVersions: 0` but that's less common. On the exam, look for options that include `isLive: false`.
Only one action is applied per object per day, but it is unpredictable which rule takes precedence. It's best to avoid overlapping conditions. Google Cloud evaluates all rules and applies the first matching action, but the order is not guaranteed. To avoid conflicts, design rules with mutually exclusive conditions.
Yes, you can transition to a warmer class (e.g., from Coldline to Standard) using SetStorageClass action. However, this incurs a Class B operation cost. Lifecycle rules are not limited to colder transitions. The exam may include scenarios where you need to move data to Standard for temporary increased access.
Lifecycle rules are evaluated approximately once per day. There is no guarantee of exactly 24 hours; it can take up to 48 hours in some cases. This is important for exam questions about timing: do not expect immediate changes.
`age` is a relative number of days from object creation (e.g., 30 days). `createdBefore` is an absolute date (e.g., '2023-01-01'). Use `age` for rolling policies (e.g., delete after 90 days) and `createdBefore` for one-time cleanup (e.g., delete everything created before a specific date).
You've just covered Cloud Storage Lifecycle Rules — now see how well it sticks with free ACE practice questions. Full explanations included, no account needed.
Done with this chapter?