简体   繁体   中英

CloudFormation: Cannot create policy for SNS topic on AWS using serveless framework

Can't figure out what I am doing wrong, if I comment out the SNSAddTopicPolicy, everything works fine, however once uncommented I get:

SNSAddTopicPolicy - Invalid parameter: Policy Error: null (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: 26870c3b-4829-5080-bd88-59e9524c08e4).

I have tried every single combination but can't get it to work, any help?

BucketAddEventInterfaceSNSTopic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: accounts-bucket-add-interface-dev

 SNSAddTopicPolicy:
    Type: AWS::SNS::TopicPolicy
    Properties:
        PolicyDocument:
          Id: 'accounts-sns-add-policy-dev'
          Version: 2012-10-17
          Statement:
            Sid: 'accounts-sns-add-statement-dev'
            Effect: Allow
            # this probably needs narrowed down
            Principal:
              AWS: '*'
            Action: sns:Publish
            Resource: { "Ref":"BucketAddEventInterfaceSNSTopic" }
        Topics:
          - { "Ref": "BucketAddEventInterfaceSNSTopic" }

It looks like you're mixing JSON and YAML syntax for the REF. Also, just to be safe you should put quotes around your version as shown below.

Your Policy should look more like this

 SNSAddTopicPolicy:
    Type: AWS::SNS::TopicPolicy
    Properties:
        PolicyDocument:
          Id: 'accounts-sns-add-policy-dev'
          Version: '2012-10-17'
          Statement:
            Sid: 'accounts-sns-add-statement-dev'
            Effect: Allow
            # this probably needs narrowed down
            Principal:
              AWS: '*'
            Action: sns:Publish
            Resource: !Ref BucketAddEventInterfaceSNSTopic
        Topics:
          - !Ref BucketAddEventInterfaceSNSTopic

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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