Work around BucketAlreadyOwnedByYou

Buckets outside of the standard region will raise an error if you try
create them and they already exist. See:
https://forums.aws.amazon.com/thread.jspa?threadID=119095
This commit is contained in:
Andrew Snowden
2014-05-29 18:23:29 +02:00
parent eba97b4ea6
commit ca86134782
+8 -1
View File
@@ -184,7 +184,14 @@ def create_all(app, user=None, password=None, bucket_name=None,
conn = S3Connection(user, password) # connect to s3
# get_or_create bucket
try:
bucket = conn.create_bucket(bucket_name, location=location)
try:
bucket = conn.create_bucket(bucket_name, location=location)
except S3CreateError as e:
if e.error_code == u'BucketAlreadyOwnedByYou':
bucket = conn.get_bucket(bucket_name)
else:
raise e
bucket.make_public(recursive=True)
except S3CreateError as e:
raise e