Sns事件主题和sqs事件队列的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 事件主题
订阅队列名称: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
假设您已经有了 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 主题不共享相同的堆栈,您需要将其传递到您的模板中,这可以作为 parameter or by using the Export feature to define a global value that you can use by referencing it with the Fn::ImportValue 内部函数来完成。
在 lambda 中
Subscription:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn: !ImportValue sns-topic-arn
FunctionName: !GetAtt Function.Arn
Enabled: true
BatchSize: 1
我有 A 服务,我们有 sns 主题和 B 服务 sqs 队列事件。
从B服务云形成我需要将云形成YAML文件写入SNS事件主题和SNS事件队列之间的订阅。
sns 主题名称:sns 事件主题
订阅队列名称: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
假设您已经有了 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 主题不共享相同的堆栈,您需要将其传递到您的模板中,这可以作为 parameter or by using the Export feature to define a global value that you can use by referencing it with the Fn::ImportValue 内部函数来完成。
在 lambda 中
Subscription:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn: !ImportValue sns-topic-arn
FunctionName: !GetAtt Function.Arn
Enabled: true
BatchSize: 1