Search code examples
pythongoogle-app-enginegoogle-cloud-storagebucket

Creating and Deleting Buckets Programmatically in Google Cloud Storage


I am using Google App Engine and Google Cloud Storage. I would like to create a bucket daily using a cron job. Also, delete a bucket programmatically. I was able to manually create a bucket using the Google Cloud Console.

How do I create/delete buckets from GAE using python?

Also, is it a good design choice to create a new bucket everyday?

Note: I am new to Google Cloud Storage.


Solution

  • It's probably not the best idea to create a new bucket every day. There's not a lot of harm in it, but there's also no advantage, as a single bucket can grow to be pretty much as big as you might ever need. It's generally a better idea to use different buckets for logically different kinds of data.

    As far as how to do it, the answer depends on the library you use. A good option is gcloud-python. Using that library:

    from gcloud import storage
    client = storage.Client()
    client.create_bucket("BucketName")