Skip to content

Commit

Permalink
Fix S3 Bucket TTLs by setting them on bucket creation not ACLing.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 559594916
  • Loading branch information
pmkc authored and copybara-github committed Aug 24, 2023
1 parent 9702d6d commit 3833a32
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions perfkitbenchmarker/providers/aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ def MakeBucket(self, bucket_name, raise_on_failure=True, tag_bucket=True):
'--tagging', 'TagSet=[%s]' % tag_set,
'--region=%s' % self.region])

if object_storage_service.OBJECT_TTL_DAYS.value:
# NOTE: buckets created with older APIs may have a different configuration
# (e.g. Prefix instead of Filter): This needs to stay updated for new
# buckets.
config = json.dumps(
{
'Rules': [{
'Expiration': {
'Days': object_storage_service.OBJECT_TTL_DAYS.value
},
'ID': 'PKB_OBJECT_TTL',
'Filter': {},
'Status': 'Enabled',
}]
}
)
vm_util.IssueCommand(util.AWS_PREFIX + [
's3api', 'put-bucket-lifecycle-configuration',
'--region', self.region,
'--bucket', bucket_name,
'--lifecycle-configuration', config])

def Copy(self, src_url, dst_url, recursive=False):
"""See base class."""
cmd = ['aws', 's3', 'cp', '--region', self.region]
Expand Down Expand Up @@ -158,27 +180,6 @@ def MakeBucketPubliclyReadable(self, bucket, also_make_writable=False):
'--bucket', bucket, '--policy',
_MakeS3BucketPolicy(bucket, actions)
])
if object_storage_service.OBJECT_TTL_DAYS.value:
# NOTE: buckets created with older APIs may have a different configuration
# (e.g. Prefix instead of Filter): This needs to stay updated for new
# buckets.
config = json.dumps(
{
'Rules': [{
'Expiration': {
'Days': object_storage_service.OBJECT_TTL_DAYS.value
},
'ID': 'PKB_OBJECT_TTL',
'Filter': {},
'Status': 'Enabled',
}]
}
)
vm_util.IssueCommand(util.AWS_PREFIX + [
'put-bucket-lifecycle-configuration',
'--region', self.region,
'--bucket', bucket,
'--lifecycle-configuration', config])

def GetDownloadUrl(self, bucket, object_name, use_https=True):
"""See base class."""
Expand Down

0 comments on commit 3833a32

Please sign in to comment.