在 python 中使用 boto 在 Amazon AWS 中创建 S3 存储桶失败 ...

Creating a S3 bucket in Amazon AWS with boto in python fails ...

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 存储桶吗?

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

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