Skip to content

Commit 84a1328

Browse files
committed
best effort to determine the AWS region for the s3 bucket. fix #1
1 parent e67f714 commit 84a1328

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

letslambda.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,16 @@ def lambda_handler(event, context):
491491
exit(1)
492492
s3_bucket = event['bucket']
493493

494-
if 'region' not in event:
495-
LOG.error("No bucket region has been provided. Exiting.")
494+
if 'region' not in event.keys() and 'AWS_DEFAULT_REGION' not in os.environ.keys():
495+
LOG.error("Unable to determine AWS region code. Exiting.")
496496
exit(1)
497-
s3_region = event['region']
497+
else:
498+
if 'region' not in event.keys():
499+
LOG.warning("Using local environment to determine AWS region code.")
500+
s3_region = os.environ['AWS_DEFAULT_REGION']
501+
LOG.warning("Local region set to '{0}'.".format(s3_region))
502+
else:
503+
s3_region = event['region']
498504

499505
if 'defaultkey' not in event:
500506
LOG.info("No default KMS key provided, defaulting to 'AES256'.")

0 commit comments

Comments
 (0)