Skip to content

Instantly share code, notes, and snippets.

@dsandor
Last active March 19, 2023 14:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dsandor/ac260aaf4d2d69e35106230adfe5db3b to your computer and use it in GitHub Desktop.
Save dsandor/ac260aaf4d2d69e35106230adfe5db3b to your computer and use it in GitHub Desktop.
CloudFormation Template Example - Subscribe a Lambda to an SNS Topic
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