Search code examples
google-cloud-storagegoogle-cloud-python

Creating bucket in Google Cloud Storage in custom location


I would like to create a bucket in GCS based in Europe using the python client.

from google.cloud import storage

Instantiates a client

storage_client = storage.Client()

The name for the new bucket

bucket_name = 'my-new-bucket'

Creates the new bucket

bucket = storage_client.create_bucket(bucket_name)

print('Bucket {} created.'.format(bucket.name))

This creates the bucket multiregional in the US. How can I change this to Europe?


Solution

  • The create_bucket method is limited. For more parameters, you'd create a bucket resource and invoke its create() method, like so:

    storage_client = storage.Client()
    bucket = storage_client.bucket('bucket-name')
    bucket.create(location='EU')
    

    Bucket.create has a few other properties and is documented: https://googleapis.github.io/google-cloud-python/latest/storage/buckets.html#google.cloud.storage.bucket.Bucket.create