Skip to content

Commit

Permalink
[AWS] Add tags on bucket creation time (#3922)
Browse files Browse the repository at this point in the history
* add tags on creation time

* Update comments and docs

---------

Co-authored-by: Romil Bhardwaj <[email protected]>
  • Loading branch information
shashank2000 and romilbhardwaj authored Sep 9, 2024
1 parent 272226b commit d46fb63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/source/reference/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Available fields and semantics:
# Advanced AWS configurations (optional).
# Apply to all new instances but not existing ones.
aws:
# Tags to assign to all instances launched by SkyPilot (optional).
# Tags to assign to all instances and buckets created by SkyPilot (optional).
#
# Example use case: cost tracking by user/team/project.
#
Expand Down
14 changes: 14 additions & 0 deletions sky/data/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,20 @@ def _create_s3_bucket(self,
s3_client.create_bucket(**create_bucket_config)
logger.info(
f'Created S3 bucket {bucket_name!r} in {region or "us-east-1"}')

# Add AWS tags configured in config.yaml to the bucket.
# This is useful for cost tracking and external cleanup.
bucket_tags = skypilot_config.get_nested(('aws', 'labels'), {})
if bucket_tags:
s3_client.put_bucket_tagging(
Bucket=bucket_name,
Tagging={
'TagSet': [{
'Key': k,
'Value': v
} for k, v in bucket_tags.items()]
})

except aws.botocore_exceptions().ClientError as e:
with ux_utils.print_exception_no_traceback():
raise exceptions.StorageBucketCreateError(
Expand Down

0 comments on commit d46fb63

Please sign in to comment.