Skip to content

Commit

Permalink
uniquify bucket names as a work-around to Issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Culich committed Oct 18, 2014
1 parent c3635f5 commit 2466bd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
24 changes: 6 additions & 18 deletions aws-iam/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,12 @@ def destroy(target):
pass

response = s3 = boto.connect_s3()
bucket = s3.get_bucket(target)
keys = bucket.list()
bucket.delete_keys([k.name for k in keys])

### The delete_bucket is intentionally commented out because the
### delete behavior is surprising relative to other delete
### operations in the API. Creating a bucket with the same name as
### one that has been deleted may not even be possible in some
### cases. Typically it takes a few hours for the bucket names to
### be cleared so in practice it is often possible to create a new
### bucket with the same name. Read more at:
### http://psykidellic.github.io/posts/amazon-s3---careful-with-bucket-names/
### https://forums.aws.amazon.com/thread.jspa?threadID=37532
### Interestingly, create_bucket does not behave as expected,
### either; if a bucket already exists, the call to create_bucket
### does not raise an exception about a duplicate
### already existing.
# s3.delete_bucket(target)
## only delete bucket names created with uniquify suffix
## Further details: https://github.com/ucberkeley/brc-experiments/issues/4
for b in s3.get_all_buckets():
if b.name.contains('-uq'):
b.delete_keys([k.name for k in b.list()])
s3.delete_bucket(b.name)

for category in ['instructors','students']:
group = target + '-' + category
Expand Down
7 changes: 6 additions & 1 deletion aws-iam/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import random
import logging
import re
import uuid

from iampolicies import apply_policy

Expand Down Expand Up @@ -93,7 +94,11 @@ def save_credentials(target, category, creds):
def provision(target):
create_signin_url(target)
s3 = boto.connect_s3()
bucket = s3.create_bucket(target)
## create bucket names with uniquify suffix
## Further details: https://github.com/ucberkeley/brc-experiments/issues/4
uniquify = 'uq' + str(uuid.uuid4())[:5]
bucket_name = target + '-' + uniquify
bucket = s3.create_bucket(bucket_name)
for category in ['instructors','students']:
creds = create_iam_users(target, category)
save_credentials(target, category, creds)
Expand Down

0 comments on commit 2466bd8

Please sign in to comment.