使用boto将目录上传到s3 [英] upload a directory to s3 with boto

查看:299
本文介绍了使用boto将目录上传到s3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经连接到实例,我想将python脚本生成的文件直接上传到S3。我已经尝试过:

I am already connected to the instance and I want to upload the files that are generated from my python script directly to S3. I have tried this:

import boto
s3 = boto.connect_s3()
bucket = s3.get_bucket('alexandrabucket')
from boto.s3.key import Key
key = bucket.new_key('s0').set_contents_from_string('some content')

,但这是在我要将目录s0上载到mybucket的同时,使用上下文 same content创建一个新文件s0。

but this is rather creating a new file s0 with the context "same content" while I want to upload the directory s0 to mybucket.

我也看过s3put,但我没能得到想要的东西。

I had a look also to s3put but I didn't manage to get what I want.

推荐答案

boto 库本身没有任何东西可以让您上传整个目录。您可以编写自己的代码以使用 os.walk 或类似文件遍历目录,并使用boto上传每个文件。

There is nothing in the boto library itself that would allow you to upload an entire directory. You could write your own code to traverse the directory using os.walk or similar and to upload each individual file using boto.

boto中有一个名为 s3put 的命令行实用程序可以解决此问题,也可以使用 AWS CLI工具,该工具具有许多功能,使您可以上传整个目录,甚至可以将S3存储桶与本地目录同步,反之亦然。

There is a command line utility in boto called s3put that could handle this or you could use the AWS CLI tool which has a lot of features that allow you to upload entire directories or even sync the S3 bucket with a local directory or vice-versa.

这篇关于使用boto将目录上传到s3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆