Last active
March 19, 2023 14:22
-
-
Save dsandor/ac260aaf4d2d69e35106230adfe5db3b to your computer and use it in GitHub Desktop.
CloudFormation Template Example - Subscribe a Lambda to an SNS Topic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Description: > | |
example-lambda-sns | |
Example CloudFormation template to subscribe a lambda to an SNS Topic. | |
Resources: | |
ExampleTopic: | |
Type: AWS::SNS::Topic | |
Properties: | |
DisplayName: !Sub 'example-sns-topic' | |
TopicName: !Sub 'example-sns-topic' | |
Subscription: | |
- Protocol: lambda | |
Endpoint: !GetAtt ExampleFunction.Arn | |
ExampleFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: ./ | |
Handler: index.handler | |
Runtime: nodejs8.10 | |
ExampleFunctionInvokePermission: | |
Type: 'AWS::Lambda::Permission' | |
Properties: | |
Action: 'lambda:InvokeFunction' | |
FunctionName: !Ref ExampleFunction | |
Principal: sns.amazonaws.com | |
ExampleTopicPolicy: | |
Type: 'AWS::SNS::TopicPolicy' | |
Properties: | |
Topics: | |
- !Ref ExampleTopic | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: 'sns:Publish' | |
Resource: !Ref ExampleTopic | |
Principal: | |
AWS: '*' | |
Condition: | |
ArnLike: | |
AWS:SourceArn: !Sub 'arn:aws:*:*:${AWS::AccountId}:*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment