jbrown
jbrown

Reputation: 7986

How to set a GCS object lifecycle for all objects below a path, not bucket-wide?

The docs only mention setting an object lifecycle for an entire bucket. However I want to set lifecycles for several paths within a bucket, but not for the entire bucket.

Is this possible on Google Cloud Storage? If so, how can I do it?

Upvotes: 8

Views: 2713

Answers (2)

Lorenzo Felletti
Lorenzo Felletti

Reputation: 553

If I understand your question correctly, what you want to achieve is having a lifecycle rule restricted to only certain subpaths. You can achieve this by setting Conditions on the rule.

Object lifecycle rules can combine multiple conditions. If you want a certain lifecycle to be applied only to a specific sub-path of the bucket, you can combine the condition you want to apply to that sub-path the condition matches prefix.

For example, if you want to set the object storage class to Nearline only for objects in the sub-path goToNearline/, you can achive this by creating a lifecycle rule like the following:

How to "restrict" a lifecycle rule to certain sub-paths

Yes, the lifecycle rule is still applied to the bucket-level, but the condition restricts its application, so this is virtually equivalent to having it set only for a specific sub-path.

Upvotes: 0

Mike Schwartz
Mike Schwartz

Reputation: 12145

It's not possible to configure lifecycle management for less than an entire bucket.

Upvotes: 7

Related Questions