SNS 不向 SQS 发送消息
SNS does not send messages to SQS
我有 2 个 SNS(订单完成、客户操作)和 2 个 SQS(通知-监听、customerPortal-监听),我的团队通过 Terraform 创建了这 4 个资源。
订单完成(SNS)-> 通知监听(SQS)它在 3 个月前装箱并且工作正常。
customer-operations(SNS) -> customerPortal-listen(SQS) 现在装箱并且消息不会发布到 sqs。
社交网络:
resource "aws_sns_topic" "order-finalized" {
name = "order-finalized"
kms_master_key_id = "alias/aws/sns"
tags = {
Name = "order-finalized",
Environment = "dev"
}
}
resource "aws_sns_topic" "customer-operations" {
name = "customer-operations"
kms_master_key_id = "alias/aws/sns"
tags = {
Name = "customer-operations",
Environment = "dev"
}
}
SQS:
resource "aws_sqs_queue" "notification-listen" {
name = "notification-listen"
delay_seconds = 0
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.deadletter.arn
maxReceiveCount = 1
})
tags = {
Name = "notification-listen"
Environment = "dev"
}
}
resource "aws_sqs_queue" "customerPortal-listen" {
name = "customerPortal-listen"
delay_seconds = 0
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.deadletter.arn
maxReceiveCount = 1
})
tags = {
Name = "customerPortal-listen"
Environment = "dev"
}
}
订阅:
resource "aws_sns_topic_subscription" "order-finalized-target" {
topic_arn = aws_sns_topic.order-finalized.arn
protocol = "sqs"
endpoint = aws_sqs_queue.notification-listen.arn
}
resource "aws_sns_topic_subscription" "customer-operations-target" {
topic_arn = aws_sns_topic.customer-operations.arn
protocol = "sqs"
endpoint = aws_sqs_queue.customerPortal-listen.arn
}
感谢@ErvinSzilagyi
我刚刚添加了一个策略,它解决了我的问题。我将 post terraform 代码供那些将在 google
上搜索该想法的人使用
resource "aws_sqs_queue_policy" "customerPortal-listen-policy" {
queue_url = aws_sqs_queue.customerPortal-listen.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "sqspolicy",
"Statement": [
{
"Sid": "First",
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "${aws_sqs_queue.customerPortal-listen.arn}",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "${aws_sns_topic.customer-operations.arn}"
}
}
}
]
}
POLICY
}
我有 2 个 SNS(订单完成、客户操作)和 2 个 SQS(通知-监听、customerPortal-监听),我的团队通过 Terraform 创建了这 4 个资源。
订单完成(SNS)-> 通知监听(SQS)它在 3 个月前装箱并且工作正常。
customer-operations(SNS) -> customerPortal-listen(SQS) 现在装箱并且消息不会发布到 sqs。
社交网络:
resource "aws_sns_topic" "order-finalized" {
name = "order-finalized"
kms_master_key_id = "alias/aws/sns"
tags = {
Name = "order-finalized",
Environment = "dev"
}
}
resource "aws_sns_topic" "customer-operations" {
name = "customer-operations"
kms_master_key_id = "alias/aws/sns"
tags = {
Name = "customer-operations",
Environment = "dev"
}
}
SQS:
resource "aws_sqs_queue" "notification-listen" {
name = "notification-listen"
delay_seconds = 0
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.deadletter.arn
maxReceiveCount = 1
})
tags = {
Name = "notification-listen"
Environment = "dev"
}
}
resource "aws_sqs_queue" "customerPortal-listen" {
name = "customerPortal-listen"
delay_seconds = 0
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.deadletter.arn
maxReceiveCount = 1
})
tags = {
Name = "customerPortal-listen"
Environment = "dev"
}
}
订阅:
resource "aws_sns_topic_subscription" "order-finalized-target" {
topic_arn = aws_sns_topic.order-finalized.arn
protocol = "sqs"
endpoint = aws_sqs_queue.notification-listen.arn
}
resource "aws_sns_topic_subscription" "customer-operations-target" {
topic_arn = aws_sns_topic.customer-operations.arn
protocol = "sqs"
endpoint = aws_sqs_queue.customerPortal-listen.arn
}
感谢@ErvinSzilagyi
我刚刚添加了一个策略,它解决了我的问题。我将 post terraform 代码供那些将在 google
上搜索该想法的人使用resource "aws_sqs_queue_policy" "customerPortal-listen-policy" {
queue_url = aws_sqs_queue.customerPortal-listen.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "sqspolicy",
"Statement": [
{
"Sid": "First",
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "${aws_sqs_queue.customerPortal-listen.arn}",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "${aws_sns_topic.customer-operations.arn}"
}
}
}
]
}
POLICY
}