in sdlf-foundations/lambda/topic/src/lambda_function.py [0:0]
def adjust_subscriptions(event, logger):
"""
Adjusts subscription according to the parameters informed into the Custom Resource.
:param event: Event sent from CFN when the custom resource is created
:param logger: Logger used for Lambda messages sent to CloudWatch
"""
resource_properties = event['ResourceProperties']
team_name = resource_properties['TeamName']
topic_arn = resource_properties['TopicArn']
subscription_protocol = resource_properties['SubscriptionProtocol']
subscription_endpoints = resource_properties['SubscriptionEndpoints']
old_resource_properties = event['OldResourceProperties'] if 'OldResourceProperties' in event else None
old_subscription_endpoints = old_resource_properties[
'SubscriptionEndpoints'] if old_resource_properties else None
if subscription_endpoints:
for endpoint in subscription_endpoints:
if old_subscription_endpoints is None or endpoint not in old_subscription_endpoints:
subscribe_endpoint(logger, team_name, topic_arn,
endpoint, subscription_protocol)
if old_subscription_endpoints:
for endpoint in old_subscription_endpoints:
if subscription_endpoints is None or endpoint not in subscription_endpoints:
unsubscribe_endpoint(logger, team_name, topic_arn, endpoint)