Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ETL-107] Add SQS template and config #60

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/develop/namespaced/sqs-queue.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
83 changes: 83 additions & 0 deletions templates/sqs-queue.yaml
Original file line number Diff line number Diff line change
@@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better

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