2012-05-05 145 views
2

我想在我的EC2實例上安裝一些Python模塊。我有我需要在S3存儲桶上進行安裝的文件。我也可以通過Python boto從我的EC2實例連接到S3存儲桶,但是我無法訪問存儲桶內容以獲取我需要安裝的源文件。如何從EC2實例導航到S3存儲桶文件夾?

回答

2

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

+2

謝謝,工作很棒:)。對於那些查看這篇文章的人來說,您需要使用s3cmd get命令從S3存儲桶和s3cmd同步下載文件以同步整個目錄樹 – user1261046

5

以防萬一你想通過博託獲得在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) 
+0

可能希望將此代碼粘貼到您的答案中,以便答案沒有依靠外部網站。 –

相關問題