Merge pull request #3072 from bblommers/cloudformation-check-name-in-use
CloudFormation - Check stack name in use
This commit is contained in:
commit
09c061e8a8
3 changed files with 41 additions and 4 deletions
|
|
@ -50,6 +50,12 @@ class CloudFormationResponse(BaseResponse):
|
|||
for item in self._get_list_prefix("Tags.member")
|
||||
)
|
||||
|
||||
if self.stack_name_exists(new_stack_name=stack_name):
|
||||
template = self.response_template(
|
||||
CREATE_STACK_NAME_EXISTS_RESPONSE_TEMPLATE
|
||||
)
|
||||
return 400, {"status": 400}, template.render(name=stack_name)
|
||||
|
||||
# Hack dict-comprehension
|
||||
parameters = dict(
|
||||
[
|
||||
|
|
@ -82,6 +88,12 @@ class CloudFormationResponse(BaseResponse):
|
|||
template = self.response_template(CREATE_STACK_RESPONSE_TEMPLATE)
|
||||
return template.render(stack=stack)
|
||||
|
||||
def stack_name_exists(self, new_stack_name):
|
||||
for stack in self.cloudformation_backend.stacks.values():
|
||||
if stack.name == new_stack_name:
|
||||
return True
|
||||
return False
|
||||
|
||||
@amzn_request_id
|
||||
def create_change_set(self):
|
||||
stack_name = self._get_param("StackName")
|
||||
|
|
@ -564,6 +576,15 @@ CREATE_STACK_RESPONSE_TEMPLATE = """<CreateStackResponse>
|
|||
</CreateStackResponse>
|
||||
"""
|
||||
|
||||
CREATE_STACK_NAME_EXISTS_RESPONSE_TEMPLATE = """<ErrorResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
|
||||
<Error>
|
||||
<Type>Sender</Type>
|
||||
<Code>AlreadyExistsException</Code>
|
||||
<Message>Stack [{{ name }}] already exists</Message>
|
||||
</Error>
|
||||
<RequestId>950ff8d7-812a-44b3-bb0c-9b271b954104</RequestId>
|
||||
</ErrorResponse>"""
|
||||
|
||||
UPDATE_STACK_RESPONSE_TEMPLATE = """<UpdateStackResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
|
||||
<UpdateStackResult>
|
||||
<StackId>{{ stack.stack_id }}</StackId>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue