Merge pull request #1586 from DHager/accept_non_json_redrive_policy
Fix Cloudformation not accepting non-JSON SQS redrive policy
This commit is contained in:
commit
bc1bdd7ae1
@ -234,11 +234,17 @@ class Queue(BaseModel):
|
|||||||
|
|
||||||
self.last_modified_timestamp = now
|
self.last_modified_timestamp = now
|
||||||
|
|
||||||
def _setup_dlq(self, policy_json):
|
def _setup_dlq(self, policy):
|
||||||
try:
|
|
||||||
self.redrive_policy = json.loads(policy_json)
|
if isinstance(policy, six.text_type):
|
||||||
except ValueError:
|
try:
|
||||||
raise RESTError('InvalidParameterValue', 'Redrive policy does not contain valid json')
|
self.redrive_policy = json.loads(policy)
|
||||||
|
except ValueError:
|
||||||
|
raise RESTError('InvalidParameterValue', 'Redrive policy is not a dict or valid json')
|
||||||
|
elif isinstance(policy, dict):
|
||||||
|
self.redrive_policy = policy
|
||||||
|
else:
|
||||||
|
raise RESTError('InvalidParameterValue', 'Redrive policy is not a dict or valid json')
|
||||||
|
|
||||||
if 'deadLetterTargetArn' not in self.redrive_policy:
|
if 'deadLetterTargetArn' not in self.redrive_policy:
|
||||||
raise RESTError('InvalidParameterValue', 'Redrive policy does not contain deadLetterTargetArn')
|
raise RESTError('InvalidParameterValue', 'Redrive policy does not contain deadLetterTargetArn')
|
||||||
|
@ -148,10 +148,41 @@ dummy_import_template = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dummy_redrive_template = {
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Resources": {
|
||||||
|
"MainQueue": {
|
||||||
|
"Type": "AWS::SQS::Queue",
|
||||||
|
"Properties": {
|
||||||
|
"QueueName": "mainqueue.fifo",
|
||||||
|
"FifoQueue": True,
|
||||||
|
"ContentBasedDeduplication": False,
|
||||||
|
"RedrivePolicy": {
|
||||||
|
"deadLetterTargetArn": {
|
||||||
|
"Fn::GetAtt": [
|
||||||
|
"DeadLetterQueue",
|
||||||
|
"Arn"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"maxReceiveCount": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"DeadLetterQueue": {
|
||||||
|
"Type": "AWS::SQS::Queue",
|
||||||
|
"Properties": {
|
||||||
|
"FifoQueue": True
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dummy_template_json = json.dumps(dummy_template)
|
dummy_template_json = json.dumps(dummy_template)
|
||||||
dummy_update_template_json = json.dumps(dummy_update_template)
|
dummy_update_template_json = json.dumps(dummy_update_template)
|
||||||
dummy_output_template_json = json.dumps(dummy_output_template)
|
dummy_output_template_json = json.dumps(dummy_output_template)
|
||||||
dummy_import_template_json = json.dumps(dummy_import_template)
|
dummy_import_template_json = json.dumps(dummy_import_template)
|
||||||
|
dummy_redrive_template_json = json.dumps(dummy_redrive_template)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
@ -746,3 +777,19 @@ def test_stack_with_imports():
|
|||||||
output = output_stack.outputs[0]['OutputValue']
|
output = output_stack.outputs[0]['OutputValue']
|
||||||
queue = ec2_resource.get_queue_by_name(QueueName=output)
|
queue = ec2_resource.get_queue_by_name(QueueName=output)
|
||||||
queue.should_not.be.none
|
queue.should_not.be.none
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sqs
|
||||||
|
@mock_cloudformation
|
||||||
|
def test_non_json_redrive_policy():
|
||||||
|
cf = boto3.resource('cloudformation', region_name='us-east-1')
|
||||||
|
|
||||||
|
stack = cf.create_stack(
|
||||||
|
StackName="test_stack1",
|
||||||
|
TemplateBody=dummy_redrive_template_json
|
||||||
|
)
|
||||||
|
|
||||||
|
stack.Resource('MainQueue').resource_status\
|
||||||
|
.should.equal("CREATE_COMPLETE")
|
||||||
|
stack.Resource('DeadLetterQueue').resource_status\
|
||||||
|
.should.equal("CREATE_COMPLETE")
|
||||||
|
Loading…
Reference in New Issue
Block a user