Mike
Mike

Reputation: 4255

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?

Upvotes: 3

Views: 1538

Answers (2)

Cyril3635
Cyril3635

Reputation: 1

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))

Upvotes: 0

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38369

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

Upvotes: 5

Related Questions