【发布时间】:2020-05-27 14:06:20
【问题描述】:
我正在尝试使用 python 中的 boto3 在 AWS 的每个区域中创建一个 s3 存储桶,但我未能在 4 个区域(af-south-1、eu-south-1、ap-east- 1 & me-south-1)
我的python代码:
def create_bucket(name, region):
s3 = boto3.client('s3')
s3.create_bucket(Bucket=name, CreateBucketConfiguration={'LocationConstraint': region})
我得到的例外:
botocore.exceptions.ClientError: An error occurred (InvalidLocationConstraint) when calling the CreateBucket operation: The specified location-constraint is not valid
我可以从 aws 网站在这些区域中创建存储桶,但这对我不利,所以我尝试直接从其余 API 中创建它,而不使用 boto3。
网址:bucket-name.s3.amazonaws.com
正文:
<?xml version="1.0" encoding="UTF-8"?>
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LocationConstraint>eu-south-1</LocationConstraint>
</CreateBucketConfiguration>
但响应类似于异常:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidLocationConstraint</Code>
<Message>The specified location-constraint is not valid</Message>
<LocationConstraint>eu-south-1</LocationConstraint>
<RequestId>********</RequestId>
<HostId>**************</HostId>
</Error>
有谁知道为什么我可以从网站手动操作,但不能从 python 操作?
【问题讨论】:
-
您使用区域 S3 端点,还是仅使用全球旧端点“s3.amazonaws.com”?对于虚拟主机,旧端点仅适用于旧区域,不适用于新区域。也许 REST API 也一样?
-
你是对的!有什么方法可以让 boto3 使用新 URL 而不是旧 URL?
标签: python amazon-web-services rest amazon-s3 boto3