Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(cloudformation): Ref to a list parameter should return a list, not a string (#1964)
mishukdutta-czb0d277b2c1d0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9982c108..d87ef1b7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -56,6 +56,10 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **CloudFormation — `Fn::Select` in a condition** — a condition that checks one member of a `CommaDelimitedList`, such as `!Not [!Equals [!Select [2, !Ref KeySpec], ""]]`, was always true, whatever the parameter value. Templates use this check for an optional member: `"id,S,,"` gives `["id", "S", "", ""]`, and an empty member means "no value". Conditions did not resolve `Fn::Select`, so `Fn::Equals` compared the unresolved function with `""`. Thus the stack made resources whose condition is false, and `Fn::If` took the wrong branch. Conditions now resolve `Fn::Select`, with the same comma split as resource properties. Contributed by @mishukdutta-cz.+### Fixed++- **CloudFormation — `Ref` to a list parameter** — a `Ref` to a `CommaDelimitedList` or `List<...>` parameter gave one string, such as `"attr_a, attr_b"`, not a list. Resource code that loops over a list property used each character as one item: `NonKeyAttributes: !Ref Projected` gave a GSI with the attributes `a`, `t`, `t`, `r`, and so on, and `!Join ["|", !Ref Projected]` gave `a|t|t|r|...`. `Ref` now gives a list, such as `["attr_a", "attr_b"]`. A template that uses this `Ref` as a string can now fail, as on AWS: an output `Value: !Ref Names` or a nested-stack parameter `Names: !Ref Names` rolls back the stack. A string property, such as the `Value` of an `AWS::SSM::Parameter`, now gets the list, not `a,b`. To use the list as one string, use `!Join [",", !Ref Names]`. Contributed by @mishukdutta-cz.+## [1.5.20] — 2026-10-01### Addeddiff --git a/ministack/services/cloudformation/engine.py b/ministack/services/cloudformation/engine.pyindex d143b967..a66b8369 100644--- a/ministack/services/cloudformation/engine.py+++ b/ministack/services/cloudformation/engine.py@@ -574,14 +574,11 @@ def _resolve_parameters(template: dict, provided_params: list[dict],except ValueError:raise ValueError(f"Parameter '{name}' value '{value}' is not a valid List<Number>")- elif ptype == "CommaDelimitedList":- # Keep as string; Fn::Select will split- pass# AWS-specific types treated as String -- no extra validation_check_parameter_constraints(name, defn, ptype, value)- out = {"Value": value, "NoEcho": no_echo}+ out = {"Value": value, "NoEcho": no_echo, "Type": ptype}if ssm_name is not None:# Persisted so a later UpdateStack with UsePreviousValue re-resolves# the SSM name instead of reusing this now-stale resolved value.@@ -1077,7 +1074,12 @@ def _resolve_refs(value, resources, params, conditions, mappings,if ref in pseudo:return pseudo[ref]if ref in params:- return params[ref]["Value"]+ param = params[ref]+ _, is_list = _rule_inner_type(param.get("Type", "String"))+ if is_list:+ # A list parameter is kept as one string: "a, b" becomes ["a", "b"]+ return [m.strip() for m in param["Value"].split(",")]+ return param["Value"]# Resource physical IDif ref in resources and "PhysicalResourceId" in resources[ref]:return resources[ref]["PhysicalResourceId"]diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex 0b7adfec..77ee11ea 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -4205,6 +4205,9 @@ def _cfn_nested_stack_deploy(logical_id, props, parent_stack_name, *,raw_param_props = props.get("Parameters") or {}if isinstance(raw_param_props, dict):+ if any(isinstance(v, list) for v in raw_param_props.values()):+ # AWS fails a list here, for example a Ref to a CommaDelimitedList+ raise ValueError("Value of property Parameters must be an object with String (or simple type) properties")provided_params = [{"Key": k, "Value": "" if v is None else str(v)}for k, v in raw_param_props.items()diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex cfbdda55..7b11f6f9 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -576,6 +576,64 @@ def test_cfn_nested_stack_stays_in_parent_region():pass+def test_cfn_ref_to_list_parameter_gives_a_list(cfn, ddb):+ """A Ref to a CommaDelimitedList gives a list of its members, without the spaces after the commas."""+ name = f"cfn-list-ref-{_uuid_mod.uuid4().hex[:8]}"+ template = {+ "Parameters": {"Projected": {"Type": "CommaDelimitedList", "Default": "attr_a, attr_b"}},+ "Resources": {"Table": {"Type": "AWS::DynamoDB::Table", "Properties": {+ "TableName": name,+ "BillingMode": "PAY_PER_REQUEST",+ "AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"},+ {"AttributeName": "gpk", "AttributeType": "S"}],+ "KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],+ "GlobalSecondaryIndexes": [{+ "IndexName": "gsi",+ "KeySchema": [{"AttributeName": "gpk", "KeyType": "HASH"}],+ "Projection": {"ProjectionType": "INCLUDE", "NonKeyAttributes": {"Ref": "Projected"}},+ }],+ }}},+ "Outputs": {"Joined": {"Value": {"Fn::Join": ["|", {"Ref": "Projected"}]}}},+ }+ try:+ cfn.create_stack(StackName=name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, name)+ assert stack["StackStatus"] == "CREATE_COMPLETE"+ assert _output(stack, "Joined") == "attr_a|attr_b"+ projection = ddb.describe_table(TableName=name)["Table"]["GlobalSecondaryIndexes"][0]["Projection"]+ # AWS does not keep the order of NonKeyAttributes+ assert sorted(projection["NonKeyAttributes"]) == ["attr_a", "attr_b"]+ finally:+ _delete_cfn_test_stack(cfn, name)+++def test_cfn_nested_stack_fails_a_list_parameter(cfn, s3):+ """A list in nested-stack Parameters fails the stack resource. A template must pass a string, for example with+ Fn::Join."""+ name = f"cfn-nested-list-{_uuid_mod.uuid4().hex[:8]}"+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")+ child = {"Parameters": {"Names": {"Type": "String"}}, "Resources": {}}+ parent = {+ "Parameters": {"Names": {"Type": "CommaDelimitedList", "Default": "a,b"}},+ "Resources": {"Child": {"Type": "AWS::CloudFormation::Stack", "Properties": {+ "TemplateURL": f"{endpoint}/{name}/child.json",+ "Parameters": {"Names": {"Ref": "Names"}},+ }}},+ }+ s3.create_bucket(Bucket=name)+ s3.put_object(Bucket=name, Key="child.json", Body=json.dumps(child))+ try:+ cfn.create_stack(StackName=name, TemplateBody=json.dumps(parent))+ assert _wait_stack(cfn, name)["StackStatus"] == "ROLLBACK_COMPLETE"+ failed = [e["ResourceStatusReason"] for e in cfn.describe_stack_events(StackName=name)["StackEvents"]+ if e["LogicalResourceId"] == "Child" and e["ResourceStatus"] == "CREATE_FAILED"]+ assert failed == ["Value of property Parameters must be an object with String (or simple type) properties"]+ finally:+ _delete_cfn_test_stack(cfn, name)+ s3.delete_object(Bucket=name, Key="child.json")+ s3.delete_bucket(Bucket=name)++_E2E_STACK = "e2e-test"_E2E_TEMPLATE = """