From c877266f8648664045b7be9fa2519269c898b825 Mon Sep 17 00:00:00 2001 From: Brandon Bradley Date: Wed, 29 Jan 2020 16:27:56 -0600 Subject: [PATCH] fix 500 error on non-existing stack name --- moto/cloudformation/models.py | 2 ++ moto/cloudformation/responses.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index 0ae5d1ae4..c05783fb4 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -677,6 +677,8 @@ class CloudFormationBackend(BaseBackend): def list_stack_resources(self, stack_name_or_id): stack = self.get_stack(stack_name_or_id) + if stack is None: + return [] return stack.stack_resources def delete_stack(self, name_or_stack_id): diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index bf68a6325..7effb03fa 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -229,6 +229,9 @@ class CloudFormationResponse(BaseResponse): stack_name_or_id = self._get_param("StackName") resources = self.cloudformation_backend.list_stack_resources(stack_name_or_id) + if not resources: + raise ValidationError(stack_name_or_id) + template = self.response_template(LIST_STACKS_RESOURCES_RESPONSE) return template.render(resources=resources)