I have a AWS lambda which sends notification to SNS topic.
Lambda Function
def send_sns_notification(message):
sns = boto3.client('sns')
response = sns.publish(
TopicArn='arn:aws:sns:ca-central-1:xxxxx',
Message=message,
MessageAttributes={
'AWS.SNS.SMS.SenderID': {
'DataType': 'String',
'StringValue': 'Airflow'
},
'AWS.SNS.SMS.SMSType': {
'DataType': 'String',
'StringValue': 'Transactional'
}
}
)
And we use cloud formation template to deploy SNS Topic
, AWS Lambda
and SNS Subscription
. How do I access the ARN for the topic created through CloudFormation.
Cloud Formation Template
Lambda:
Type: AWS::Serverless::Function
Properties:
Description: sends sns notification if dag in airflow fails
FunctionName: "airflow-notification"
Handler: send_sns_notification.py
Runtime: python3.6
ReservedConcurrentExecutions: !Ref AWS::NoValue
Role: !FindInMap [EnvVariables, Parameters, LambdaRole]
VpcConfig:
SecurityGroupIds:
- !FindInMap [EnvVariables, Parameters, VPCSecurityGroupId]
SubnetIds:
- !FindInMap [EnvVariables, Parameters, VPCSubnetId1]
- !FindInMap [EnvVariables, Parameters, VPCSubnetId2]
SNSTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: !FindInMap [EnvVariables, Parameters, SNSTopicName]
DisplayName: airflow
KmsMasterKeyId: !FindInMap [EnvVariables, Parameters, SNSCMK]
SNSSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: [email protected]
Protocol: email
TopicArn: !Ref 'SNSTopic'