简体   繁体   中英

Amazon AWS SQS - Apply QueuePolicy to existing Queue

if i am creating an SQS Queue via Cloudformation, are you able to attach an second QueuePolicy after the SQS Queue has been created?

if i do run this following config:

Resources:
  SQSQueue:
    Properties:
      QueueName: !Ref SQSQueuename
    Type: 'AWS::SQS::Queue'
  QueuePolicy:
    Type: 'AWS::SQS::QueuePolicy'
    Properties:
      PolicyDocument:
        Id: !Ref SQSQueuename
        Statement:
          - Sid: QueuePolicy2-SendMessage-To-Queue-From-SNS-Topic
            Effect: Allow
            Principal:
              AWS: !Ref AccountID
            Action:
              - 'sqs:*'
            Resource: 'arn:aws:sqs:eu-central-1:123456789010:${SQSQueuename}'
      Queues:
        - !Ref SQSQueue 
   DependsOn:
     - SQSQueue

Are i am able to create another QueuePolicy attached to the created Queue? And How would i attach it? Via ARN?

Resources:
  SecondQueuePolicy:
    Type: 'AWS::SQS::QueuePolicy'
    Properties:
      PolicyDocument:
        Id: !Ref SQSQueuename
        Statement:
          - Sid: QueuePolicy2-SendMessage-To-Queue-From-SNS-Topic
            Effect: Allow
            Principal:
              AWS: !Ref AccountID
            Action:
              - 'sqs:*'
            Resource: 'arn:aws:sqs:eu-central-1:123456789010:${SQSQueuename}'
      Queues:
        - !Ref SQSQueue <-- how do i ref to the Queue ?
   DependsOn:
     - SQSQueue

In your first template make sure you export the queue URL and name:

Outputs: 
  QueueURL: 
    Value: !Ref SQSQueue
    Export:
      Name: ExampleStack-QueueURL
  QueueName: 
    Value: !GetAtt SQSQueue.QueueName
    Export:
      Name: ExampleStack-QueueName

In the second template import the newly exported values (no need for DependsOn):

  SecondQueuePolicy:
    Type: 'AWS::SQS::QueuePolicy'
    Properties:
      PolicyDocument:
        Id: !Ref SQSQueuename
        Statement:
          - Sid: QueuePolicy2-SendMessage-To-Queue-From-SNS-Topic
            Effect: Allow
            Principal:
              AWS: !Ref AccountID
            Action:
              - 'sqs:*'
            Resource:
              Fn::Sub:
                - 'arn:aws:sqs:eu-central-1:123456789010:${QueueName}'
                - QueueName:
                    Fn::ImportValue: ExampleStack-QueueName
      Queues:
        - Fn::ImportValue: ExampleStack-QueueURL

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