Skip to content

Commit

Permalink
Merge branch 'main' of github.com:awslabs/serverless-rules into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoutschen committed Jul 7, 2021
2 parents 8ae0ba6 + b6c68da commit 431f44d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cfn-lint-serverless/cfn_lint_serverless/rules/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from cfnlint.rules import CloudFormationLintRule, RuleMatch

from ..utils import Value


class SqsNoRedrivePolicyRule(CloudFormationLintRule):
"""
Expand All @@ -24,12 +26,19 @@ def match(self, cfn):
Match against SQS queues without RedrivePolicy
"""

matches = []
matches = {}
dlqs = []

for key, value in cfn.get_resources(["AWS::SQS::Queue"]).items():
redrive_policy = value.get("Properties", {}).get("RedrivePolicy", None)

if redrive_policy is None:
matches.append(RuleMatch(["Resources", key], self._message.format(key)))
matches[key] = RuleMatch(["Resources", key], self._message.format(key))

else:
redrive_policy = Value(redrive_policy)
# If a queue is used as a DLQ, it doesn't need a redrive policy
# See https://github.com/awslabs/serverless-rules/issues/79
dlqs.extend(redrive_policy.references)

return matches
return [v for k, v in matches.items() if k not in dlqs]
15 changes: 15 additions & 0 deletions cfn-lint-serverless/tests/templates/es6000-multiple.pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test for https://github.com/awslabs/serverless-rules/issues/79
AWSTemplateFormatVersion: "2010-09-09"

Resources:
Queue:
Type: AWS::SQS::Queue
Properties:
RedrivePolicy: !Sub |
{
"deadLetterTargetArn": "${DLQ}",
"maxReceiveCount": 4
}
DLQ:
Type: AWS::SQS::Queue

0 comments on commit 431f44d

Please sign in to comment.