Skip to content

bug: Cloudformation doesn't validate the format of the TemplateBody during a stack creation #12309

@pinzon

Description

@pinzon

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

create_stack = client.create_stack(StackName='test',TemplateBody=template_url)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cristopher/Work/triaging/cdklocal_bootstrapping/app/.venv/lib/python3.12/site-packages/botocore/client.py", line 569, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cristopher/Work/triaging/cdklocal_bootstrapping/app/.venv/lib/python3.12/site-packages/botocore/client.py", line 1023, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InternalError) when calling the CreateStack operation (reached max retries: 4): exception while calling cloudformation.CreateStack: Traceback (most recent call last):
  File "/opt/code/localstack/.venv/lib/python3.11/site-packages/rolo/gateway/chain.py", line 166, in handle
    handler(self, self.context, response)
  File "/opt/code/localstack/localstack-core/localstack/aws/handlers/service.py", line 113, in __call__
    handler(chain, context, response)
  File "/opt/code/localstack/localstack-core/localstack/aws/handlers/service.py", line 83, in __call__
    skeleton_response = self.skeleton.invoke(context)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack-core/localstack/aws/skeleton.py", line 154, in invoke
    return self.dispatch_request(serializer, context, instance)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack-core/localstack/aws/skeleton.py", line 168, in dispatch_request
    result = handler(context, instance) or {}
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack-core/localstack/aws/skeleton.py", line 118, in __call__
    return self.fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack-core/localstack/aws/api/core.py", line 163, in operation_marker
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack-core/localstack/services/cloudformation/provider.py", line 221, in create_stack
    stack_name = template["StackName"] = request.get("StackName")
                 ~~~~~~~~^^^^^^^^^^^^^
TypeError: 'str' object does not support item assignment

Expected Behavior

create_stack = client.create_stack(StackName='test',TemplateBody=template_url)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cristopher/Work/triaging/cdklocal_bootstrapping/app/.venv/lib/python3.12/site-packages/botocore/client.py", line 569, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cristopher/Work/triaging/cdklocal_bootstrapping/app/.venv/lib/python3.12/site-packages/botocore/client.py", line 1023, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the CreateStack operation: Template format error: unsupported structure.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

import boto3
client = boto3.client('cloudformation', endpoint_url="http://localhost:4566")
template_url = "https://raw.githubusercontent.com/aws-cloudformation/aws-cloudformation-templates/refs/heads/main/EC2/InstanceWithCfnInit.yaml"

create_stack = client.create_stack(StackName='test',TemplateBody=template_url)

Environment

- OS:
- LocalStack:
  LocalStack version:
  LocalStack Docker image sha:
  LocalStack build date:
  LocalStack build git hash:

Anything else?

Could be related to #12305

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions