在 Google Cloud Storage 中的自定义位置创建存储桶

Mik*_*ike 3 google-cloud-storage google-cloud-python

我想使用 python 客户端在欧洲的 GCS 中创建一个存储桶。

from google.cloud import storage
Run Code Online (Sandbox Code Playgroud)

实例化一个客户端

storage_client = storage.Client()
Run Code Online (Sandbox Code Playgroud)

新存储桶的名称

bucket_name = 'my-new-bucket'
Run Code Online (Sandbox Code Playgroud)

创建新存储桶

bucket = storage_client.create_bucket(bucket_name)

print('Bucket {} created.'.format(bucket.name))
Run Code Online (Sandbox Code Playgroud)

这将在美国创建多区域存储桶。我怎样才能将其更改为欧洲?

Bra*_*ugh 5

方法create_bucket有限。对于更多参数,您可以创建一个存储桶资源并调用其create()方法,如下所示:

storage_client = storage.Client()
bucket = storage_client.bucket('bucket-name')
bucket.create(location='EU')
Run Code Online (Sandbox Code Playgroud)

Bucket.create 还有一些其他属性并记录在案:https://googleapis.github.io/google-cloud-python/latest/storage/buckets.html#google.cloud.storage.bucket.Bucket.create