Creates a S3 directory bucket :returns: the name of the bucket created
(session, name=None, location=None)
| 218 | |
| 219 | |
| 220 | def create_dir_bucket(session, name=None, location=None): |
| 221 | """ |
| 222 | Creates a S3 directory bucket |
| 223 | :returns: the name of the bucket created |
| 224 | """ |
| 225 | if not location: |
| 226 | location = ('us-west-2', 'usw2-az1') |
| 227 | region, az = location |
| 228 | client = session.create_client('s3', region_name=region) |
| 229 | if name: |
| 230 | bucket_name = name |
| 231 | else: |
| 232 | bucket_name = f"{random_bucket_name()}--{az}--x-s3" |
| 233 | params = { |
| 234 | 'Bucket': bucket_name, |
| 235 | 'CreateBucketConfiguration': { |
| 236 | 'Location': {'Type': 'AvailabilityZone', 'Name': az}, |
| 237 | 'Bucket': { |
| 238 | 'Type': 'Directory', |
| 239 | 'DataRedundancy': 'SingleAvailabilityZone', |
| 240 | }, |
| 241 | }, |
| 242 | } |
| 243 | try: |
| 244 | client.create_bucket(**params) |
| 245 | except ClientError as e: |
| 246 | if e.response['Error'].get('Code') == 'BucketAlreadyOwnedByYou': |
| 247 | # This can happen in the retried request, when the first one |
| 248 | # succeeded on S3 but somehow the response never comes back. |
| 249 | # We still got a bucket ready for test anyway. |
| 250 | pass |
| 251 | else: |
| 252 | raise |
| 253 | return bucket_name |
| 254 | |
| 255 | |
| 256 | def random_chars(num_chars): |
no test coverage detected