简体   繁体   中英

How can I navigate into S3 bucket folders from EC2 instance?

I would like to install some Python modules on my EC2 instance. I have the files I need for the installation on an S3 bucket. I can also connect from my EC2 instance to the S3 bucket through Python boto, but I cannot access the bucket contents to get the source files I need installed.

Just in case you want to get the files in Python via boto, here's a simple example:

https://gist.github.com/1925584

And in case you don't like following links:

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM