没有使用无服务器创建SNS订阅

时间:2019-03-04 18:57:02

标签: aws-lambda amazon-sns serverless

我有一个无服务器项目,该项目应部署一个队列,将该队列订阅到现有主题,并使用lambda处理队列外的消息。这是我的yaml:

service: "ssul-${opt:branch}"

provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-1

functions:
  update:
    reservedConcurrency: 10
    handler: index.update
    events:
    - sqs:
        arn: {Fn::GetAtt: [Queue, Arn]}
        batchSize: 1

resources:
  Resources:
    Queue:
      Type: "AWS::SQS::Queue"
      Properties:
        MessageRetentionPeriod: 10800
        VisibilityTimeout: 900
        QueueName: "updates-${opt:branch}"
    Subscription:
      Type: "AWS::SNS::Subscription"
      Properties:
        TopicArn: "${env:TOPIC_ARN}"
        Protocol: sqs
        Endpoint:
          Fn::GetAtt: [Queue, Arn]

我运行sls deploy --branch master返回正常,除订阅外,所有内容均已部署。该主题在另一个帐户中,但是我能够创建一个队列并通过控制台手动订阅。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题(在我的情况下,我使用的是SAM-无服务器应用程序模型,因此我的yml不同,但问题应该相同)。有时,控制台会在后台创建一些对象。就我而言,问题是主题策略资源:

  TopicPolicy:
    Type: "AWS::SNS::TopicPolicy"
    Properties:
      PolicyDocument:
        Version: "2012-10-17"
        Id: MyTopicPolicy
        Statement:
          - 
            Effect: "Allow"
            Principal: 
              Service: "events.amazonaws.com"
            Action: 
              - "sns:Publish"
            Resource: "*"
      Topics:
        - !Ref PipelineNotificationsTopic