【问题标题】:Creating a S3 bucket in Amazon AWS with boto in python fails ...在 python 中使用 boto 在 Amazon AWS 中创建 S3 存储桶失败...
【发布时间】:2015-09-16 18:14:42
【问题描述】:
import boto
import boto.s3
import boto.s3.connection

conn = boto.s3.connect_to_region(
'us-west-2', 
aws_access_key_id='MY_KEY', 
aws_secret_access_key='MY_ACCESS_KEY'
)

conn.create_bucket('bucket_in_west')

我得到这个错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/user/.virtualenvs/west-tests/lib/python2.7/site-packages/boto/s3/connection.py", line 621, in create_bucket
    response.status, response.reason, body)
S3ResponseError: S3ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>IllegalLocationConstraintException</Code><Message>The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.</Message><RequestId>0C0F09FBC87

有人知道如何使用 boto 在特定区域创建 S3 存储桶吗?

【问题讨论】:

    标签: python amazon-web-services amazon-s3 amazon boto


    【解决方案1】:

    如果您正在与us-west-2 端点通信并且您想在该区域创建一个存储桶,您必须在调用create_bucket 时指定:

    conn.create_bucket('bucket-in-west', location='us-west-2')
    

    【讨论】:

    • 这也适用于法兰克福地区吗? (该地区不同的身份验证握手版本 - 不知道为什么)
    • 是的,它适用于任何地区。如果您希望存储桶位于该区域中,则应连接到该区域中的 S3 端点,然后在 create_bucketlocation 参数中指定该区域。
    • 嗨,米奇,感谢您的 cmets。像往常一样非常有帮助。不过需要注意的一件事......当连接到特定于区域的 S3 服务时,无法创建名称中包含“_”/下划线的存储桶......
    猜你喜欢
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 2014-04-22
    • 2020-05-04
    • 2017-12-25
    • 2018-09-14
    相关资源
    最近更新 更多