简体   繁体   English

使用 Cloudformation 发布 AWS SNS 到 SQS 失败

[英]AWS SNS to SQS publish fails using Cloudformation

I've recently started learning and implementing services using AWS services.我最近开始使用 AWS 服务学习和实施服务。 So, I guess I'm missing some small steps which I can't figure it.所以,我想我错过了一些我无法理解的小步骤。

I'm trying to implement the following diagram using the Cloudformation template.我正在尝试使用 Cloudformation 模板实现下图。 Everything is working fine unless.除非一切正常。 The Lambda and SQS queue are subscribed to the SNS topic successfully. Lambda 和 SQS 队列订阅 SNS 主题成功。 Whenever a file is stored at the bucket, or even when I publish a message to the SNS topic manually, the lambda function is triggered successfully, but the message is not published to the SQS queue.每当文件存储在存储桶中时,甚至当我手动向 SNS 主题发布消息时,lambda function 都会成功触发,但消息不会发布到 SQS 队列。 I've also added the AWS::SQS::QueuePolicy to allow SNS to send messages to SQS, but it still does not work.我还添加了 AWS::SQS::QueuePolicy 以允许 SNS 向 SQS 发送消息,但它仍然不起作用。

AWS 架构

template.yml:模板.yml:

...

Resources:
  S3ObjectPutTopic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: !Sub ${AppName}-vrp-creation-${Environment}-topic

  BucketToSNSPermission:
    Type: AWS::SNS::TopicPolicy
    ...

  Bucket:
    Type: AWS::S3::Bucket
    ...

  Lambda:
    Type: AWS::Serverless::Function
    ...

  Queue:
    Type: AWS::SQS::Queue
    Properties:
      DelaySeconds: 0
      MaximumMessageSize: 262144
      MessageRetentionPeriod: 864000
      QueueName: !Sub ${AppName}-${Environment}-queue
      ReceiveMessageWaitTimeSeconds: 0
      VisibilityTimeout: 90

  TopicToQueuePermission:
    Type: AWS::SQS::QueuePolicy
    Properties:
      Queues:
        - !Ref Queue
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service: s3.amazonaws.com
            Action: sqs:SendMessage
            Resource: !GetAtt Queue.Arn
            Condition:
              ArnEquals:
                aws:SourceArn: !Ref S3ObjectPutTopic

  TopicToQueueSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: sqs
      TopicArn: !Ref S3ObjectPutTopic
      Endpoint: !GetAtt Queue.Arn
      RawMessageDelivery: true

The full Cloudformation template.yaml file:template.yaml完整的 Cloudformation 模板.yaml 文件:template.yaml

You have mentioned Service: s3.amazonaws.com instead of Service: sns.amazonaws.com in your SQS policy.您在 SQS 策略中提到了Service: s3.amazonaws.com而不是Service: sns.amazonaws.com Update the template and try.更新模板并尝试。

TopicToQueuePermission:
Type: AWS::SQS::QueuePolicy
Properties:
  Queues:
    - !Ref Queue
  PolicyDocument:
    Version: 2012-10-17
    Statement:
      - Effect: Allow
        Principal:
          Service: s3.amazonaws.com
        Action: sqs:SendMessage
        Resource: !GetAtt Queue.Arn
        Condition:
          ArnEquals:
            aws:SourceArn: !Ref S3ObjectPutTopic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM