3

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?

Mike
  • 3,775
  • 8
  • 39
  • 79

2 Answers2

4

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

Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
0

You can try with this:

def create_bucket(bucket_name):
    storage_client = storage.Client()
    bucket = storage_client.create_bucket(bucket_name, location='EUROPE-WEST1')
    print("Bucket {} created".format(bucket.name))
janw
  • 8,758
  • 11
  • 40
  • 62