【问题标题】:Creating bucket in Google Cloud Storage in custom location在自定义位置的 Google Cloud Storage 中创建存储桶
【发布时间】:2019-03-04 22:03:34
【问题描述】:

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

from google.cloud import storage

实例化一个客户端

storage_client = storage.Client()

新存储桶的名称

bucket_name = 'my-new-bucket'

创建新存储桶

bucket = storage_client.create_bucket(bucket_name)

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

这会在美国创建多区域存储桶。如何将其更改为欧洲?

【问题讨论】:

    标签: google-cloud-storage google-cloud-python


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      你可以试试这个:

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

      【讨论】:

        猜你喜欢
        • 2015-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-03
        • 1970-01-01
        • 1970-01-01
        • 2021-03-06
        相关资源
        最近更新 更多