Skip to content

Commit

Permalink
fix(cdk-ops): ignore invalid keys
Browse files Browse the repository at this point in the history
- Fixes the bug that `lambda/delete-access-logs` crashed when an empty
  folder was created in the S3 bucket. It ignores the event if the
  object key ends with a slash; i.e., the last segment is empty.

issue codemonger-io#30
  • Loading branch information
kikuomax committed Oct 11, 2022
1 parent b669dc0 commit ae03435
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cdk-ops/lambda/delete-access-logs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ def process_s3_object(s3_object):
# so the last segment separated by a slash ('/') is the key for the
# original access logs file.
src_key = key.split('/')[-1]
src = source_bucket.Object(src_key)
try:
res = src.delete()
LOGGER.debug('deleted object "%s": %s', src_key, str(res))
except ClientError as exc:
LOGGER.error('failed to delete object "%s": %s', src_key, str(exc))
if len(src_key) > 0:
src = source_bucket.Object(src_key)
try:
res = src.delete()
LOGGER.debug('deleted object "%s": %s', src_key, str(res))
except ClientError as exc:
LOGGER.error('failed to delete object "%s": %s', src_key, str(exc))
else:
LOGGER.warning('ignoring invalid key: %s', key)

0 comments on commit ae03435

Please sign in to comment.