[英]How to create and subscribe an Amazon SQS queue to an Amazon SNS topic in AWS CloudFormation?
[英]How to write the cloudformation subscription between Sns event topic and sqs event queue
我有 A 服务,我们有 sns 主题和 B 服务 sqs 队列事件。
从 B 服务云形成我需要编写云形成 YAML 文件来订阅 SNS 事件主题和 SNS 事件队列之间的订阅。
sns 主题名称: sns-event-topic
订阅队列名称: abcd-events
Resources: AbcdEventQueue: Type: "AWS::SQS::Queue" Properties: QueueName: "abcd-events" AbcdEventQueuePolicy: Type: "AWS::SQS::QueuePolicy" Properties: Queues: - Ref: "AbcdEventQueue" PolicyDocument: Statement: - Effect: "Allow" Principal: AWS: '*' Action: - sqs:SendMessage - sqs:ReceiveMessage - sqs:DeleteMessage - sqs:GetQueueUrl - sqs:GetQueueAttributes - sqs:ListQueueTags - sqs:ChangeMessageVisibility Resource: -.GetAtt AbcdEventQueue.Arn
在 lambda
Subscription:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn: !ImportValue sns-topic-arn
FunctionName: !GetAtt Function.Arn
Enabled: true
BatchSize: 1
假设您已经拥有 SNS 主题,您将创建一个AWS::SNS::Subscription
资源。
它看起来像下面的结构
Subscription:
Type: 'AWS::SNS::Subscription'
Properties:
TopicArn: !Ref TopicArn #You will need to provide the SNS Topic Arn here
Endpoint: !GetAtt
- AbcdEventQueue
- Arn
Protocol: sqs
RawMessageDelivery: 'true'
如果SNS 主题不共享相同的堆栈,则需要将其传递到模板中,这可以作为参数完成,也可以通过使用导出功能来定义全局值,您可以通过Fn 引用它来使用它: :ImportValue内在 function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.