Created
November 11, 2021 16:32
-
-
Save mrollinsiv/dfa22ccbf415afe3e70911f895f0ea61 to your computer and use it in GitHub Desktop.
SNS Fanout in Serverless Framework
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
org: barstool | |
app: service1 | |
service: demo | |
provider: | |
name: aws | |
resources: | |
Resources: | |
MyOutputTopic: | |
Type: 'AWS::SNS::Topic' | |
Properties: | |
TopicName: MyOutput-${opt:stage} | |
Outputs: | |
MyOutputTopic: | |
Value: !Ref MyOutputTopic | |
Export: | |
Name: MyOutputTopic-${opt:stage} | |
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
org: barstool | |
app: service2 | |
service: demo | |
provider: | |
name: aws | |
resources: | |
Resources: | |
# Create a basic queue | |
Service2Queue: | |
Type: 'AWS::SQS::Queue' | |
Properties: | |
QueueName: Service2-${opt:stage} | |
VisibilityTimeout: 60 | |
# Create an SNS subscription for the queue above | |
Service2Subscription: | |
Type: 'AWS::SNS::Subscription' | |
Properties: | |
TopicArn: MyOutputTopic-${opt:stage} | |
Endpoint: | |
Fn::GetAtt: [Service2Queue, Arn] | |
Protocol: sqs | |
RawMessageDelivery: 'true' | |
# Provide the proper permissions for Service2Queue to recieve messages from MyOutputTopic-{$opt:stage} | |
Service2QueuePolicy: | |
Type: AWS::SQS::QueuePolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Principal: '*' | |
Action: SQS:SendMessage | |
Resource: | |
- Fn::GetAtt: [Service2Queue, Arn] | |
Condition: | |
ArnEquals: | |
AWS:SourceArn: MyOutputTopic-${opt:stage} | |
Queues: | |
- !Ref Service2Queue | |
functions: | |
MyOutputTopicQueue: | |
handler: handlers/sqs.myOutputTopic | |
events: | |
- sqs: | |
arn: | |
Fn::GetAtt: [Service2Queue, Arn] | |
batchSize: 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment