How can I configure a cloud storage bucket to hold data only for a single day?

0 votes
I want to configure a bucket such that it holds data in it only for 24 hours and automatically deletes it after the time elapses. How do I do that? Can somebody help me with it?
Nov 21 in GCP by anonymous
• 6,650 points
15 views

1 answer to this question.

0 votes

Suppose you only want to keep files in a particular bucket around for just one day, then you can set up the lifecycle rule for the bucket with:

echo '{ "rule": [{ "action": {"type": "Delete"}, "condition": {"age": 1}}]}' > lifecycle_config.json
gsutil lifecycle set lifecycle_config.json gs://example-bucket

Now, any objects in your bucket older than a day will automatically get deleted from this bucket. 

You can verify the configuration you just set with the gsutil lifecycle command (other configuration commands work in a similar fashion):

gsutil lifecycle get gs://example-bucket
answered Nov 21 by Sirajul
• 40,980 points

Related Questions In GCP

0 votes
1 answer
0 votes
1 answer

GCP Error: 403: Access Denied

Check that your credentials are correct. For ...READ MORE

answered Oct 9 in GCP by Sirajul
• 40,980 points
32 views
0 votes
1 answer

Permissions issue with Google Cloud Storage Bucket.

You can regain access to the object by assigning an applicable role, like roles/storage.objectAdmin, to ...READ MORE

answered Oct 10 in GCP by Sirajul
• 40,980 points
93 views
0 votes
1 answer