python - aws s3下载文件

标签 python amazon-s3 amazon-ec2

我正在尝试从我的 Amazon s3 存储桶之一下载文件到 Ubuntu EC2 实例。我在 2 个不同区域创建了两个存储桶,我可以从一个区域的存储桶访问和下载文件,但是当我尝试访问时另一个面临着问题。

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

但是我可以从另一个区域的存储桶中下载文件。

最佳答案

您可以在连接 Amazon S3 时指定区域。

波托

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')

关于python - aws s3下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46031337/

相关文章:

multiprocessing.pool 中的 Python ThreadPool 无法利用所有 CPU

python - 如何让子项迭代并最终迭代 AWS S3 中子项内的文件

swift - 列出 AWS S3 存储桶中的所有对象

tomcat - AWS 数据传输问题

amazon-web-services - 使用 AWS 数据管道 - EMR 与 EC2

python - 我们能够修剪预训练模型吗?示例 : MobileNetV2

python - 普通函数和生成器函数有什么区别?

python - 使用 paramiko 和 exec_command 进行 SSH

forms - 我正在使用 Amazon S3,并且想要创建一个在提交时发送电子邮件的表单。我怎样才能做到这一点?

linux - Amazon EC2 私钥丢失,如何访问服务器?