无法在s3中创建bucket

2024-09-19 23:31:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在s3中使用USEast1作为位置create a bucket。在

from boto.s3.connection import Location

mybucket = 'test-voip1'
conn = boto.connect_s3(aws_access_key_id, aws_secret_access_key)
if conn.lookup(mybucket) is None:
     conn.create_bucket(mybucket, location=Location.USEast1)
     # conn.create_bucket(mybucket)

当我尝试运行时,它会给我一个属性错误

^{pr2}$

我可以连接以创建连接,并且可以创建一个以USWest为位置的bucket。在安装boto时,我没有得到任何错误,但为什么我得到这个错误?在

即使我试过用boto3

session = boto3.Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
s3 = session.resource('s3')
s3.create_bucket(Bucket='mybucket', CreateBucketConfiguration={'LocationConstraint': 'us-east-1'})

我也有类似的错误

 botocore.exceptions.ClientError: An error occurred (InvalidLocationConstraint) when calling the CreateBucket operation: The specified location-constraint is not valid

如何解决错误?在

当我试图检查s3中其他先前创建的bucket的位置时

bucket = conn.get_bucket('ml-vectors')
bucket.get_location()
>> ''

它是空的,我无法检查其他桶是如何在我的s3中创建的。在


Tags: keyawsidsecrets3bucketaccess错误
1条回答
网友
1楼 · 发布于 2024-09-19 23:31:09

一旦查看AWS中Location类的定义,就可以理解所得到的错误连接.py公司名称:

class Location(object):

DEFAULT = ''  # US Classic Region
EU = 'EU'  # Ireland
EUCentral1 = 'eu-central-1'  # Frankfurt
USWest = 'us-west-1'
USWest2 = 'us-west-2'
SAEast = 'sa-east-1'
APNortheast = 'ap-northeast-1'
APSoutheast = 'ap-southeast-1'
APSoutheast2 = 'ap-southeast-2'
CNNorth1 = 'cn-north-1'

正如你所见,这是没有用的。这个问题的解决方案可以在下面的引文中找到:

As per http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html: "If you are creating a bucket on the US East (N. Virginia) region (us-east-1), you do not need to specify the location constraint". Other regions work fine. I can take this up.

您可以在以下网站上找到完整的讨论: https://github.com/elastic/elasticsearch/issues/16978

相关问题 更多 >