如何从EC2实例导航到S3存储桶文件夹?

时间:2012-05-05 11:22:41

标签: python amazon-s3 amazon-ec2 amazon-web-services boto

我想在我的EC2实例上安装一些Python模块。我有在S3存储桶上安装所需的文件。我也可以通过Python boto从我的EC2实例连接到S3存储桶,但我无法访问存储桶内容以获取我需要安装的源文件。

2 个答案:

答案 0 :(得分:5)

如果你想通过boto获取Python文件,这里有一个简单的例子:

https://gist.github.com/1925584

如果您不喜欢以下链接:

import boto
import os

def download_keys(bucket_name, dst_dir):
    """
    Very simple example showing how to download all keys in a bucket.
    Assumes key names don't include path separators.  Also assumes that
    you don't have zillions of objects in the bucket.  If you have a lot
    you would want to get several download operations going in parallel.
    """
    s3 = boto.connect_s3()
    bucket = s3.lookup(bucket_name)
    for key in bucket:
        path = os.path.join(dst_dir, key.name)
        key.get_contents_to_filename(path)

答案 1 :(得分:2)

使用s3cmd工具(http://s3tools.org/s3cmd)可以下载/上传存储在存储桶中的文件。