Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_async_sns_topic(self, lambda_name, lambda_arn):
"""
Create the SNS-based async topic.
"""
topic_name = get_topic_name(lambda_name)
# Create SNS topic
topic_arn = self.sns_client.create_topic(
Name=topic_name)['TopicArn']
# Create subscription
self.sns_client.subscribe(
TopicArn=topic_arn,
Protocol='lambda',
Endpoint=lambda_arn
)
# Add Lambda permission for SNS to invoke function
self.create_event_permission(
lambda_name=lambda_name,
principal='sns.amazonaws.com',
source_arn=topic_arn
)
# Add rule for SNS topic as a event source
else: # pragma: no cover
self.client = SNS_CLIENT
if kwargs.get('arn'):
self.arn = kwargs.get('arn')
else:
if kwargs.get('boto_session'):
sts_client = kwargs.get('boto_session').client('sts')
else:
sts_client = STS_CLIENT
AWS_ACCOUNT_ID = sts_client.get_caller_identity()['Account']
self.arn = 'arn:aws:sns:{region}:{account}:{topic_name}'.format(
region=self.aws_region,
account=AWS_ACCOUNT_ID,
topic_name=get_topic_name(self.lambda_function_name)
)
# Issue: https://github.com/Miserlou/Zappa/issues/1209
# TODO: Refactor
self.capture_response = capture_response
if capture_response:
if ASYNC_RESPONSE_TABLE is None:
print(
"Warning! Attempted to capture a response without "
"async_response_table configured in settings (you won't "
"capture async responses)."
)
capture_response = False
self.response_id = "MISCONFIGURED"
else:
def remove_async_sns_topic(self, lambda_name):
"""
Remove the async SNS topic.
"""
topic_name = get_topic_name(lambda_name)
removed_arns = []
for sub in self.sns_client.list_subscriptions()['Subscriptions']:
if topic_name in sub['TopicArn']:
self.sns_client.delete_topic(TopicArn=sub['TopicArn'])
removed_arns.append(sub['TopicArn'])
return removed_arns