From 2466bd8821a2a3df875e0a16a95245c7157eddc8 Mon Sep 17 00:00:00 2001 From: Aaron Culich Date: Sat, 18 Oct 2014 10:40:03 -0700 Subject: [PATCH] uniquify bucket names as a work-around to Issue #4 https://github.com/ucberkeley/brc-experiments/issues/4 --- aws-iam/destroy.py | 24 ++++++------------------ aws-iam/provision.py | 7 ++++++- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/aws-iam/destroy.py b/aws-iam/destroy.py index 3742c83..599dd4b 100755 --- a/aws-iam/destroy.py +++ b/aws-iam/destroy.py @@ -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 diff --git a/aws-iam/provision.py b/aws-iam/provision.py index 644982b..c9cb208 100755 --- a/aws-iam/provision.py +++ b/aws-iam/provision.py @@ -8,6 +8,7 @@ import random import logging import re +import uuid from iampolicies import apply_policy @@ -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)