![](/img/trans.png)
[英]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.