Is it possible to create gcp bucket that deletes themselves after a period of time?

Viewed 528

Is there a command in google cloud API or in the python library that allows to create a temporary bucket with its age as a parameter ?

I saw that bucket offers Object Lifecycle Management, but it seems that the rules applies to blobs within the bucket but not the bucket itself.

1 Answers

No, you can't auto delete the bucket. You can, indeed, set a life cycle to delete automatically the blobs but not the bucket itself

If you have to delete the bucket in the next 365 days, you can use Cloud Scheduler.

Run this command to

gcloud scheduler jobs create http delete-bucket \
  --oauth-service-account-email=<service account email>  \
  --http-method=DELETE --schedule="0 0 * * *" --time-zone=UTC \
  --uri=https://storage.googleapis.com/storage/v1/b/<your bucket name>

In this command I call the Storage DELETE api, and you can set a schedule according to this expression -> You can specify the month and the day, thus, up to the next year, not more.

You also need to have a Service account with the storage.bucket.delete permission (storage admin role)

Related