无法在s3

时间:2019-02-05 12:26:31

标签: python amazon-s3

我正在尝试将USEast1作为位置在我的s3中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)

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

Traceback (most recent call last):
   File "s2t_amazon.py", line 146, in <module>
        conn.create_bucket(mybucket, location=Location.USEast1)
AttributeError: type object 'Location' has no attribute 'USEast1'

我能够进行连接以创建连接,并且能够以USWest作为位置来创建存储桶。在安装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 = conn.get_bucket('ml-vectors')
bucket.get_location()
>> ''

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

1 个答案:

答案 0 :(得分:1)

一旦您查看AWS连接中的Location类的定义,就可以理解所得到的错误:

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'

如您所见,没有USEast1。可以在下面的引用中找到该问题的解决方案:

  

根据http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html:“如果要在美国东部(弗吉尼亚北部)区域(us-east-1)上创建存储桶,则无需指定位置约束”。   其他地区工作正常。我可以接受这个。

您可以找到有关以下内容的完整讨论: https://github.com/elastic/elasticsearch/issues/16978