2012-07-31 129 views

回答

1

从教程差不多: http://boto.s3.amazonaws.com/s3_tut.html#storing-data

from boto.s3.connection import S3Connection 
from boto.s3.key import Key 
import subprocess 

conn = S3Connection() 
buckets = conn.get_all_buckets() 
bucket = buckets[0] # assuming you have one bucket created 

output = subprocess.check_output(["echo", "Hello World!"]) 
k = Key(bucket) 
k.key = 'test' 
k.set_contents_from_string(output) # should be saved on S3 

k.get_contents_as_string()   # should retrieve the string 
+1

如果输出太大而不适合内存,该怎么办? – 2012-08-01 02:53:35

+1

雅,你是对的,没有一种很好的方式将数据“流”到一个单一的S3密钥。最好的办法是使用/创建多个键将数据分块到一个桶中,然后按照它们的顺序读出块。 – 2012-08-01 05:29:34

4

我认为答案是,你不能轻易流数据到S3,除非你知道你是流数据的大小,因为S3需要的大小预先知道的对象。您绝对可以从s3中流出数据,但为了获取数据,您需要在内存或磁盘上进行缓冲,除非您有足够的幸运知道其大小。