gpt4 book ai didi

amazon-web-services - SNS 主题未发布到 SQS

转载 作者:行者123 更新时间:2023-12-04 01:35:35 25 4
gpt4 key购买 nike

我正在尝试使用 SNS 和 SQS 对分布式应用程序进行原型(prototype)设计。我有这个主题:
arn:aws:sns:us-east-1:574008783416:us-east-1-live-auction
这个队列:
arn:aws:sqs:us-east-1:574008783416:queue4
我使用 JS Scratchpad 创建了队列。我使用控制台添加了订阅。我使用暂存器将权限添加到队列。队列策略现在是:

{  
"Version":"2008-10-17",
"Id":"arn:aws:sqs:us-east-1:574008783416:queue4/SQSDefaultPolicy",
"Statement":[
{
"Sid":"RootPerms",
"Effect":"Allow",
"Principal":{
"AWS":"574008783416"
},
"Action":"SQS:*",
"Resource":"arn:aws:sqs:us-east-1:574008783416:queue4"
}
]
}

我有关于同一主题的电子邮件订阅,并且电子邮件可以正常到达,但消息永远不会到达队列。我已经尝试使用 Scratchpad 将 SendMessage 直接发送到队列 - 而不是通过 SNS - 它工作正常。任何想法为什么它不会发送到队列?

最佳答案

大多数答案(除了@spg 答案)建议使用 principal: * - 这是非常危险的做法,它会将您的 SQS 暴露给全世界。
来自 AWS docs

For resource-based policies, such as Amazon S3 bucket policies, a wildcard (*) in the principal element specifies all users or public access.
We strongly recommend that you do not use a wildcard in the Principal element in a role's trust policy unless you otherwise restrict access through a Condition element in the policy. Otherwise, any IAM user in any account in your partition can access the role.


因此,强烈不建议使用此主体。
相反,您需要指定 sns 服务作为您的主体:
"Principal": {
"Service": "sns.amazonaws.com"
},
示例策略:
{
"Version": "2012-10-17",
"Id": "Policy1596186813341",
"Statement": [
{
"Sid": "Stmt1596186812579",
"Effect": "Allow",
"Principal": {
"Service": "sns.amazonaws.com"
},
"Action": [
"sqs:SendMessage",
"sqs:SendMessageBatch"
],
"Resource": "Your-SQS-Arn"
}
]
}
使用此策略,sns 将能够向您的 SQS 发送消息。
more permissions对于 SQS,但据我所见 SendMessageSendMessageBatch对于 SNS->SQS 订阅应该足够了。

关于amazon-web-services - SNS 主题未发布到 SQS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5926774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com