Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload a directory to s3 with boto

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') 

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

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

like image 730
user3333539 Avatar asked Aug 19 '14 10:08

user3333539


People also ask

Can you upload a directory to S3?

To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.


1 Answers

The following function can be used to upload directory to s3 via boto.

    def uploadDirectory(path,bucketname):         for root,dirs,files in os.walk(path):             for file in files:                 s3C.upload_file(os.path.join(root,file),bucketname,file) 

Provide a path to the directory and bucket name as the inputs. The files are placed directly into the bucket. Alter the last variable of the upload_file() function to place them in "directories".

like image 114
JDPTET Avatar answered Oct 02 '22 17:10

JDPTET