Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does my sqs access policy statement is overwritten instead of adding another policy?

I have a sqs queue, which has an existing sqs access policy.

I am trying to add another policy statement inside the existing policy, but running my cloudformation template results in overwriting the existing policy with the new policy.

 DlqSqsQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: !Sub name
      KmsMasterKeyId: alias/aws/sqs
      KmsDataKeyReusePeriodSeconds: 86400
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete

  DlqSqsQueuePolicy:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Fn::GetAtt:
                    - rulenamev1
                    - Arn

            Effect: Allow
            Principal:
              Service: events.amazonaws.com
            Resource:
              Fn::GetAtt:
                - DlqSqsQueue
                - Arn
            Sid: v1
        Version: '2012-10-17'
      Queues:
        - Ref: DlqSqsQueue

  DlqSqsQueuePolicyV2:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Fn::GetAtt:
                    - rulenamev2
                    - Arn
            Effect: Allow
            Principal:
              Service: events.amazonaws.com
            Resource:
              Fn::GetAtt:
                - DlqSqsQueue
                - Arn
            Sid: v2
        Version: '2012-10-17'
      Queues:
        - Ref: DlqSqsQueue

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

An SQS queue can have only one AWS::SQS::QueuePolicy. You have to take your Statement from DlqSqsQueuePolicyV2 and add it to DlqSqsQueuePolicy:

 DlqSqsQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: !Sub name
      KmsMasterKeyId: alias/aws/sqs
      KmsDataKeyReusePeriodSeconds: 86400
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete

  DlqSqsQueuePolicy:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Fn::GetAtt:
                    - rulenamev1
                    - Arn

            Effect: Allow
            Principal:
              Service: events.amazonaws.com
            Resource:
              Fn::GetAtt:
                - DlqSqsQueue
                - Arn
            Sid: v1
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Fn::GetAtt:
                    - rulenamev2
                    - Arn
            Effect: Allow
            Principal:
              Service: events.amazonaws.com
            Resource:
              Fn::GetAtt:
                - DlqSqsQueue
                - Arn
            Sid: v2            
        Version: '2012-10-17'
      Queues:
        - Ref: DlqSqsQueue
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading