Skip to content

Commit 983fa87

Browse files
committed
minor refactoring
1 parent 30dee5e commit 983fa87

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

data-exports/deploy/data-exports-aggregation.yaml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -538,35 +538,24 @@ Resources:
538538
import boto3
539539
540540
POLICY_SID = os.environ['POLICY_SID']
541+
BUCKET_NAME = os.environ['BUCKET_NAME']
542+
s3 = boto3.client('s3')
541543
542544
def lambda_handler(event, context):
543-
s3 = boto3.client('s3')
544545
action = event.get('action', 'enable') # 'enable' or 'disable'
545-
bucket_name = os.environ['BUCKET_NAME']
546-
547546
try:
548-
policy = json.loads(s3.get_bucket_policy(Bucket=bucket_name)['Policy'])
549-
547+
policy = json.loads(s3.get_bucket_policy(Bucket=BUCKET_NAME)['Policy'])
550548
# Find and modify the policy statement
551549
for statement in policy['Statement']:
552550
if statement.get('Sid') == POLICY_SID:
553551
statement['Effect'] = 'Allow' if action == 'enable' else 'Deny'
554552
break
555553
else:
556554
raise Exception(f'{POLICY_SID} statement not found in policy')
557-
558-
s3.put_bucket_policy(Bucket=bucket_name, Policy=json.dumps(policy))
559-
560-
return {
561-
'statusCode': 200,
562-
'body': f'Successfully {action}d {POLICY_SID} statement'
563-
}
564-
555+
s3.put_bucket_policy(Bucket=BUCKET_NAME, Policy=json.dumps(policy))
556+
return {'statusCode': 200, 'body': f'Successfully {action}d {POLICY_SID} statement'}
565557
except Exception as e:
566-
return {
567-
'statusCode': 500,
568-
'body': str(e)
569-
}
558+
return {'statusCode': 500, 'body': str(e) }
570559
Environment:
571560
Variables:
572561
BUCKET_NAME: !Ref DestinationS3
@@ -622,20 +611,6 @@ Resources:
622611
Principal: events.amazonaws.com
623612
SourceArn: !GetAtt EnableRuleSchedule.Arn
624613

625-
626-
627-
628-
629-
630-
631-
632-
633-
634-
635-
636-
637-
638-
639614
# CUR2
640615

641616
## Deploy Data Export natively via CFN resource in regions that support native CFN

0 commit comments

Comments
 (0)