google-cloud-storagestoragelifecycle

Is there a way to set up a delete lifecycle rule of less than one day in google cloud storage?


I am trying to delete objects in a storage bucket by setting a delete lifecycle rule. I want these objects to be deleted 2 hours after creation, but it seems like you can only set the delete rule with AGE value based on days, not hours. I saw the question here, where it seems like if you set the delete rule with AGE value to 0 days, after approx. 2 hours the rule is triggered and the objects deleted. Is it documented somewhere? Is it guaranteed to always execute like this? Or do you have any other suggestion on how I can achieve this?

I tried to set the delete rule with AGE set to 0 and I am currently trying to understand when the rule is triggered. Surely after a weekend the objects in the bucket were deleted. But after two hours from creation they were still there.


Solution

  • No, there is no workaround. 1 day is the lower bound. It typically takes a day or more for the lifecycle policies to delete the objects.

    The best practice for deleting a large amount of objects from Cloud Storage would be to use an object lifecycle rule to delete all objects within a bucket using the age=0 rule instead. While the objects may not be purged from the bucket immediately*, you will no longer be billed for storage cost as soon as the lifecycle rule is created.

    Once the objects are deleted from the bucket by the lifecycle rule, you may delete the empty bucket.

    Note*: Updates for lifecycle configuration may take up to 24 hours to go into effect as per documentation. Object Lifecycle Management may still perform actions based on the old configuration for up to 24 hours.