in aws/solutions/lambda-backed-cloudformation-custom-resources/update_endpoint_policy/lambda_function.py [0:0]
def cloudformation_update(event, context, ec2_client):
"""Cloudformation called us with CreateStack."""
if DEBUG_MODE is True:
print("Create Option: Attempting to run update")
# This should almost never be called for updates, only if a template had a bucket added or removed
original_policy_document = describe_vpc_endpoints(event, context, ec2_client)
if event['ResourceProperties']['bucket-arn'] not in original_policy_document[0]['Resource']:
# Our bucket is not in the policy, add it
original_policy_document['Statement'][0]['Resource'].append(str(event['ResourceProperties']['bucket-arn']))
original_policy_document['Statement'][0]['Resource'].append(str(event['ResourceProperties']['bucket-arn'] + '/*'))
modify_vpc_endpoint(event, context, ec2_client, original_policy_document)
else:
# Our bucket is in the policy
print("Bucket supplied is already in the policy, skipping any actions.")
response_data = {}
if event['StackId'] == '012345678910/fake-stack-id':
print("Skipping sending CloudFormation response due to local testing.")
return
send(event, context, 'SUCCESS', response_data, event['StackId'])
if DEBUG_MODE is True:
print("Exiting successfully")
return