创建SNS策略时出现无效参数错误。

huangapple go评论67阅读模式
英文:

Invalid parameter error when creating SNS policy

问题

我试图给SNS授予权限来发布到SQS队列,但我一直收到以下错误:

无效参数: 策略错误: null (服务: AmazonSNS; 状态码: 400; 错误代码: InvalidParameter; 请求ID: a5459d05-e37a-5906-92c2-c16c4813cca0; 代理: null)

我正在使用Serverless框架,并已阅读了多篇描述相同问题的帖子,但似乎没有一个修复方法起作用。以下是我的当前版本:

MyTopicPolicy:
  Type: AWS::SNS::TopicPolicy
  Properties:
    PolicyDocument:
      Id: 'allowsSNSToSQS'
      Version: '2012-10-17'
      Statement:
        Sid: AllowSNStoPublishToSQS
        Effect: Allow
        Principle: "*"
        Action: 'sqs:SendMessage'
        Resource:
          Fn::GetAtt: [MyQueue , Arn ]
        Condition:
          ArnEquals:
            aws:SourceArn: { "Ref" : "MyTopic" }
    Topics:
      - { "Ref" : "MyTopic" }

有人有任何想法吗?谢谢。

英文:

I'm trying to give SNS the permission to publish to an SQS queue but I keep getting error:

Invalid parameter: Policy Error: null (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: a5459d05-e37a-5906-92c2-c16c4813cca0; Proxy: null)

I am using the serverless framework, and have read multiple posts describing the same issue but none of the fixes seem to work, here is my current version:

MyTopicPolicy:
  Type: AWS::SNS::TopicPolicy
  Properties:
    PolicyDocument:
      Id: 'allowsSNSToSQS'
      Version: '2012-10-17'
      Statement:
        Sid: AllowSNStoPublishToSQS
        Effect: Allow
        Principle: "*"
        Action: 'sqs:SendMessage'
        Resource:
          Fn::GetAtt: [MyQueue , Arn ]
        Condition:
          ArnEquals:
            aws:SourceArn: { "Ref" : "MyTopic" }
    Topics:
      - { "Ref" : "MyTopic" }

Does anyone have any ideas? thanks

答案1

得分: 0

MyTopicPolicy:
  Type: AWS::SQS::QueuePolicy
  Properties:
    Queues:
      - {"Ref": "MyQueue"}
    PolicyDocument:
      Id: 'allowsSNSToSQS'
      Version: '2012-10-17'
      Statement:
        Sid: AllowSNStoPublishToSQS
        Effect: Allow
        Principal:
          Service: "sns.amazonaws.com"
        Action: "sqs:SendMessage"
        Resource:
          Fn::GetAtt: [MyQueue , Arn ]
        Condition:
          ArnEquals:
            aws:SourceArn: {"Ref" : "MyTopic"}
英文:

Along with the typo I was also using the wrong policy type, I should've been using AWS::SQS::QueuePolicy as can be seen below:

MyTopicPolicy:
  Type: AWS::SQS::QueuePolicy
  Properties:
    Queues: 
      - {"Ref": "MyQueue"}
    PolicyDocument:
      Id: 'allowsSNSToSQS'
      Version: '2012-10-17'
      Statement:
        Sid: AllowSNStoPublishToSQS
        Effect: Allow
        Principal:
          Service: "sns.amazonaws.com"
        Action: "sqs:SendMessage"
        Resource:
          Fn::GetAtt: [MyQueue , Arn ]
        Condition:
          ArnEquals:
            aws:SourceArn: { "Ref" : "MyTopic" }

huangapple
  • 本文由 发表于 2023年2月18日 00:24:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75486835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定