What is Lifecycle Policy?
- It is used to create rules like setting a Time to Live (TTL) for objects, or “downgrading” storage classes of objects to help save money.
- You can add a lifecycle management configuration to a bucket. You will have to add certain conditions so once an object meets the criteria of any of the rules, Cloud Storage automatically performs a specified action on the object.
Here are some example use cases:
- Adding a rule to downgrade the storage class for the objects older than 180 days to Coldline Storage.
- Adding a rule for Deletion of objects created before Dec 01, 2020.
There are two types of actions that can be specified in a lifecycle rule. i.e. Delete or SetStorageClass
- Delete: It deletes an object when the object meets the conditions specified in the lifecycle policy.
- SetStorageClass: It changes the storage class of an object when a certain object meets the specified conditions in the lifecycle policy.
Note: Updates to your lifecycle configuration rules might take up to 24 hours to take effect which means rules may still perform actions based on the old setup for up to 24 hours.
- This lab walks you through Lifecycle Policy for Cloud Storage Bucket.
- You will be adding a rule to delete an Object from your bucket after a certain time.
- Login into GCP Console.
- Creating a bucket.
- Uploading an object into your bucket.
- Adding permissions for your bucket.
- Adding lifecycle policy.
Creating a Cloud Storage Bucket and adding lifecycle policy:
- Click on the hamburger icon on the top left corner
- Click on the Cloud Storage tab.
3. Click on “create bucket”.
4. Enter the name for your bucket as “whizlabs-storage-lab”. The name should be globally unique name. Click Continue.
5. Choose the location as US and type as multi-region to get high availability. Click Continue.
6. Choose storage class as Standard.
7. Choose access control as “Uniform” to get the same access for all the objects in the bucket.
8. Click on create to finally create your bucket.
9. Choose upload files in your bucket as shown
10. Once you choose your file and upload it, it will appear like this. Object names can be different.
11. You have to add permission so that only authenticated users can see the object.
12. Click on add.
13. Enter member as allAuthenticatedUsers and Select role as Storage object viewer in Cloud Storage.
14. Click on Save to continue.
15. Click on allow public access.
16. You can see your uploaded object.
17. You can use this public URL to load your object.
18. Once you are inside your bucket, Click on the “Lifecycle tab”.
19. Click on “add a rule” to add a lifecycle policy.
20. Select action to delete an object once it satisfies a certain condition.
21. Click on continue to proceed further.
22. Opt as “Age” in the condition and mention 30 days, which means after 30 days objects will be deleted automatically.
23. Click on create to finally create the rule.
Completion and Conclusion:
- In this lab, you have created a Cloud Storage Bucket and uploaded an Object into the bucket.
- You have added a rule to delete an object after 30days of upload.
Your article helped me a lot, is there any more related content? Thanks!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/es/register-person?ref=IJFGOAID
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Reading your article has greatly helped me, and I agree with you. But I still have some questions. Can you help me? I will pay attention to your answer. thank you.