SBN*_* AB 6 python amazon-s3 amazon-web-services
我是 AWS 新手,我使用 boto3 将文件上传到 s3。但是我在配置 boto3 连接时有点困惑。下面是代码。
import boto3
s3 = boto3.resource(
's3',
aws_access_key_id='access_key',
aws_secret_access_key='secret_key'
)
data = open('test.txt', 'rb')
s3.Bucket('bucketname').put_object(Key='test.txt', Body=data)
I tried to print the bucket names using below code and it worked well.
for bucket in s3.buckets.all():
print(bucket.name)
Run Code Online (Sandbox Code Playgroud)
但是如果我给桶名
s3.Bucket('xxxxxx').put_object(Key='test.txt', Body=data)
我收到错误为:
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid bucket name "xxxxxx": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$"
Run Code Online (Sandbox Code Playgroud)
我需要这方面的帮助。
从异常情况来看,您传递的存储桶名称似乎不遵循 S3 存储桶名称限制。
\n\n\n\n从上面的链接:
\n\n\n\n\n符合 DNS 的存储桶名称规则如下:
\n\n\xe2\x80\xa2Bucket 名称长度必须至少为 3 个且不超过 63 个字符。
\n\n\xe2\x80\xa2Bucket 名称必须是一系列一个或多个标签。相邻标签\n 由单个句点 (.) 分隔。存储桶名称可以包含小写字母、数字和连字符。每个标签必须以小写字母或数字开头和结尾。
\n\n\xe2\x80\xa2Bucket 名称不得采用 IP 地址格式(例如\n 192.168.5.4)。
\n
还...
\n\n\n\n重要的
\n\n2018 年 3 月 1 日,我们更新了美国东部(弗吉尼亚北部)区域中 S3\n 存储桶的命名约定,以匹配我们在全球所有其他 AWS 区域中使用的命名约定。在此日期之后,Amazon S3 将不再支持创建包含大写字母或下划线的存储桶名称。此更改确保可以使用虚拟主机样式寻址来寻址每个存储桶,例如https://myawsbucket.s3.amazonaws.com。我们强烈建议您检查现有的存储桶创建流程,以确保遵守我们的 DNS 兼容命名约定。
\n
归档时间: |
|
查看次数: |
6832 次 |
最近记录: |