我正在尝试从我的亚马逊s3桶中下载一个文件到Ubuntu EC2实例。我在两个不同的区域创建了两个桶,我可以从一个区域的桶中访问和下载文件,但是当我试图访问另一个区域时,就会遇到问题。
Here is the error,
Traceback (most recent call last):
File "listbucket.py", line 7, in <module>
bucket = conn.get_bucket('train-faces')
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 509, in get_bucket
return self.head_bucket(bucket_name, headers=headers)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 556, in head_bucket
response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
但我可以从另一个地区的桶中下载文件。
发布于 2017-09-03 23:15:35
您可以在与Amazon连接时指定区域。
boto
import boto
conn = boto.s3.connect_to_region('ap-southeast-2')
conn.get_bucket('train-faces')
boto3
现在,建议您使用boto3
import boto3
s3 = boto3.resource('s3', region_name = 'ap-southeast-2')
bucket = s3.Bucket('train-faces')
或
import boto3
client = boto3.client('s3', region_name = 'ap-southeast-2')
发布于 2017-09-04 03:01:25
您可以使用以下命令下载
import boto3
s3 = boto3.client('s3','region_name')
s3.download_file("bucket-name", "key-name", "tmp.txt")
请参阅http://boto3.readthedocs.io/en/latest/guide/s3.html
解释-我们首先要连接到特定区域的s3。您从一个桶中获取文件的原因可能是您在配置boto时设置的值。在建立连接时提供region_name是一个很好的实践。另一个原因可能是文件不可访问或权限被拒绝。如果稍后是问题所在,那么您应该是相同的错误,表示权限被拒绝。
https://stackoverflow.com/questions/46031337
复制相似问题