首页 > 解决方案 > 创建 glcoud 存储桶时无法指定存储桶的位置

问题描述

我认为以下代码将在美国西部地区构建一个存储桶,但在我的谷歌控制台上,该地区被列为多地区。

from google.cloud import storage

storage_client = storage.Client()
bucket = storage_client.create_bucket(bucket_name)
bucket.location = 'us-west2-a'

标签: gcloudgoogle-api-client

解决方案


from google.cloud import storage

storage_client = storage.Client()
bucket = storage_client.create_bucket(bucket_name)
bucket.location = 'us-west2-a'

您的代码示例中的问题是您指定了区域名称“us-west2-a”,而不是区域(位置)名称“us-west2”。

from google.cloud import storage

storage_client = storage.Client()
bucket = storage_client.create_bucket(bucket_name)
bucket.location = 'us-west2'

通过更改为“us-west2”,它应该在所需位置创建您的存储桶。

参考:

存储 - 位置示例代码

谷歌云位置


推荐阅读