diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58966ac..554ad54 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.1.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -9,12 +9,12 @@ repos: hooks: - id: yamllint - repo: https://github.com/awslabs/cfn-python-lint - rev: v0.54.0 + rev: v0.58.4 hooks: - id: cfn-python-lint files: templates/.*\.(json|yml|yaml)$ - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.1.10 + rev: v1.1.13 hooks: - id: remove-tabs # - repo: https://github.com/pycqa/pylint diff --git a/config/develop/namespaced/sqs-queue.yaml b/config/develop/namespaced/sqs-queue.yaml new file mode 100644 index 0000000..01a4a4e --- /dev/null +++ b/config/develop/namespaced/sqs-queue.yaml @@ -0,0 +1,4 @@ +template_path: sqs-queue.yaml +stack_name: '{{ stack_group_config.namespace }}-sqs-SNSToLambda' +stack_tags: + {{ stack_group_config.default_stack_tags }} diff --git a/templates/sqs-queue.yaml b/templates/sqs-queue.yaml new file mode 100644 index 0000000..b32a48d --- /dev/null +++ b/templates/sqs-queue.yaml @@ -0,0 +1,83 @@ +AWSTemplateFormatVersion: '2010-09-09' + +Description: > + Creates an SQS queue and corresponding dead-letter queue and + subscribes that queue to an SNS topic + +Resources: + + PrimaryQueue: + Type: AWS::SQS::Queue + Properties: + DelaySeconds: 0 + MessageRetentionPeriod: 86400 + QueueName: !Sub '${AWS::StackName}-Queue' + ReceiveMessageWaitTimeSeconds: 20 + RedrivePolicy: + deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn + maxReceiveCount: 3 + VisibilityTimeout: 120 + + PrimaryQueuePolicy: + Type: AWS::SQS::QueuePolicy + Properties: + PolicyDocument: + Version: '2012-10-17' + Statement: + - Sid: Admin + Effect: Allow + Principal: + AWS: !Sub '${AWS::AccountId}' + Action: + - SQS:* + Resource: !Ref PrimaryQueue + - Sid: SNS + Effect: Allow + Principal: + AWS: '*' + Action: + - SQS:SendMessage + Resource: !Ref PrimaryQueue + Condition: + ArnEquals: + 'aws:SourceArn': !Ref SnsTopic + + Queues: + - !Ref PrimaryQueue + + DeadLetterQueue: + Type: AWS::SQS::Queue + Properties: + DelaySeconds: 0 + MessageRetentionPeriod: 1209600 + QueueName: !Sub '${AWS::StackName}-DeadLetterQueue' + ReceiveMessageWaitTimeSeconds: 10 + RedriveAllowPolicy: + redrivePermission: 'allowAll' + VisibilityTimeout: 30 + + DeadLetterQueuePolicy: + Type: AWS::SQS::QueuePolicy + Properties: + PolicyDocument: + Version: '2012-10-17' + Statement: + - Sid: Admin + Effect: Allow + Principal: + AWS: !Sub '${AWS::AccountId}' + Action: + - SQS:* + Resource: !Ref DeadLetterQueue + Queues: + - !Ref DeadLetterQueue + + SnsTopic: + Type: AWS::SNS::Topic + + SnsSubscription: + Type: AWS::SNS::Subscription + Properties: + Protocol: sqs + TopicArn: !Ref SnsTopic + Endpoint: !GetAtt PrimaryQueue.Arn