我有一个流(假设它是生成过程中的stdout),我想使用boto发送给s3。
我可以提供代码示例吗?
答案 0 :(得分:5)
我认为答案是你不能轻易地将数据流式传输到s3,除非你知道你正在流式传输的数据的大小,因为s3需要预先知道对象的大小。你绝对可以从s3流式传输数据但是为了获取数据,你需要在内存或磁盘中缓冲,除非你有幸知道它的大小。
答案 1 :(得分: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