Questions about downloading two Amazon S3 Python downloads

I am working with this code now:

#!/usr/bin/env python import boto import boto.s3 from boto.s3.key import Key AWS_ACCESS_KEY_ID = '' AWS_SECRET_ACCESS_KEY = '' filename = 'test.zip' bucket_name = AWS_ACCESS_KEY_ID.lower() + '-mah-bucket' conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) bucket = conn.create_bucket(bucket_name, location=boto.s3.connection.Location.DEFAULT) k = Key(bucket) k.key = 'my test file' k.set_contents_from_filename(filename) 

I have two questions. Firstly, I believe that this code creates a bucket and also does the loading. The fact is that I do not want to create a bucket, because I already have one in its place. To do this, I just change it to this:

 k = Key(bucket_name) 

and get rid of this:

 bucket = conn.create_bucket(bucket_name, location=boto.s3.connection.Location.DEFAULT) 
+4
source share
1 answer

Actually, instead of conn.create_bucket (...) just do:

 bucket = conn.get_bucket(bucket_name) k = Key(bucket) 

In addition, I should probably indicate that it seems silly to name your buckets based on AWS_ACCESS_KEY_ID, since this is really not necessary.

+4
source

Source: https://habr.com/ru/post/1447100/


All Articles