Skip to content

Commit

Permalink
[Storage] Make s3 bucket creation log visible to the users (#3730)
Browse files Browse the repository at this point in the history
* refactor and make log visible

* nit

* Update sky/data/storage.py

Co-authored-by: Tian Xia <[email protected]>

---------

Co-authored-by: Tian Xia <[email protected]>
  • Loading branch information
landscapepainter and cblmemo authored Jul 7, 2024
1 parent 994d35a commit 6acaa75
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions sky/data/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,24 +1368,22 @@ def _create_s3_bucket(self,
"""
s3_client = self.client
try:
if region is None:
s3_client.create_bucket(Bucket=bucket_name)
else:
if region == 'us-east-1':
# If default us-east-1 region is used, the
# LocationConstraint must not be specified.
# https://stackoverflow.com/a/51912090
s3_client.create_bucket(Bucket=bucket_name)
else:
location = {'LocationConstraint': region}
s3_client.create_bucket(Bucket=bucket_name,
CreateBucketConfiguration=location)
logger.info(f'Created S3 bucket {bucket_name} in {region}')
create_bucket_config: Dict[str, Any] = {'Bucket': bucket_name}
# If default us-east-1 region of create_bucket API is used,
# the LocationConstraint must not be specified.
# Reference: https://stackoverflow.com/a/51912090
if region is not None and region != 'us-east-1':
create_bucket_config['CreateBucketConfiguration'] = {
'LocationConstraint': region
}
s3_client.create_bucket(**create_bucket_config)
logger.info(
f'Created S3 bucket {bucket_name!r} in {region or "us-east-1"}')
except aws.botocore_exceptions().ClientError as e:
with ux_utils.print_exception_no_traceback():
raise exceptions.StorageBucketCreateError(
f'Attempted to create a bucket '
f'{self.name} but failed.') from e
f'Attempted to create a bucket {self.name} but failed.'
) from e
return aws.resource('s3').Bucket(bucket_name)

def _delete_s3_bucket(self, bucket_name: str) -> bool:
Expand Down

0 comments on commit 6acaa75

Please sign in to comment.