Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" }
like image 454
fgonzalez Avatar asked Sep 17 '25 00:09

fgonzalez


1 Answers

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
like image 55
Jaron F Avatar answered Sep 19 '25 16:09

Jaron F