Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(cloudformation): resolve AWS::SSM::Parameter::Value<...> against SSM (#1338)

ryan-bennettc03441bd93bf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48d7388e..27dad2b3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,11 @@ All notable changes to MiniStack will be documented here.
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Versioning follows [Semantic Versioning](https://semver.org/).
+## [Unreleased]
+
+### Fixed
+- **CloudFormation — `AWS::SSM::Parameter::Value<...>` template parameters now resolve against SSM Parameter Store** — a template parameter typed `AWS::SSM::Parameter::Value<String>` (or `<List<String>>` / `<AWS::EC2::Image::Id>`) takes an SSM parameter *name* as its Default/provided value; real CloudFormation resolves that name against Parameter Store before `Ref` ever sees it — the mechanism behind, e.g., CDK's `StringParameter.valueForStringParameter`. MiniStack treated these like any other AWS-specific parameter type and passed the literal name straight through, so `Ref` returned the parameter's name instead of its stored value, and any resource property built from it (or a nested stack composing two independently-deployed stacks through a shared parameter) silently received the wrong string. Resolution now looks the name up in the SSM store at parameter-resolution time; a name that doesn't exist fails `CreateStack`/`UpdateStack` synchronously with a `ValidationError`, matching AWS. Contributed by @ryan-bennett.
+
## [1.4.15] — 2026-08-10
### Added
diff --git a/ministack/services/cloudformation/engine.py b/ministack/services/cloudformation/engine.py
index 994c2ff8..49f1decc 100644
--- a/ministack/services/cloudformation/engine.py
+++ b/ministack/services/cloudformation/engine.py
@@ -130,6 +130,19 @@ _AWS_SPECIFIC_TYPES = {
"AWS::Route53::HostedZone::Id",
}
+# Unlike the other _AWS_SPECIFIC_TYPES entries (an AZ name, an AMI id, ...),
+# whose given value already *is* the value CloudFormation hands to Ref, an
+# ``AWS::SSM::Parameter::Value<...>`` parameter's given value is an SSM
+# parameter *name* — real CloudFormation resolves it against SSM Parameter
+# Store before Ref ever sees it. Kept as its own set so
+# ``AWS::SSM::Parameter::Type`` (a template-side type constraint, not an
+# SSM lookup at all) isn't accidentally swept in here too.
+_SSM_PARAMETER_VALUE_TYPES = {
+ "AWS::SSM::Parameter::Value<String>",
+ "AWS::SSM::Parameter::Value<List<String>>",
+ "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
+}
+
def _resolve_parameters(template: dict, provided_params: list[dict],
previous_params: dict | None = None) -> dict:
@@ -152,10 +165,17 @@ def _resolve_parameters(template: dict, provided_params: list[dict],
no_echo = str(defn.get("NoEcho", "false")).lower() == "true"
entry = provided_map.get(name)
+ # Whether `value` below still needs SSM-name resolution, or is
+ # already a final value — a `previous_params` hit is always the
+ # latter: it's this same parameter's *already-resolved* Value from
+ # the prior deployment (see the end of this loop, where `resolved`
+ # is built), not the SSM parameter name again.
+ already_resolved = False
if entry is not None and entry.get("UsePreviousValue"):
prev = previous_params.get(name)
if prev is not None:
value = prev["Value"] if isinstance(prev, dict) else prev
+ already_resolved = True
elif "Default" in defn:
value = defn["Default"]
else:
@@ -170,6 +190,23 @@ def _resolve_parameters(template: dict, provided_params: list[dict],
value = str(value) if value is not None else ""
+ if ptype in _SSM_PARAMETER_VALUE_TYPES and not already_resolved:
+ # `value` up to here is the SSM parameter *name* (the template
+ # parameter's Default, or a caller-supplied override) — resolve
+ # it against the SSM store the same way real CloudFormation
+ # does before Ref ever sees it. Local import to avoid a
+ # cloudformation/ssm circular import at module load time (see
+ # ecs.py's identical pattern for the same reason).
+ from ministack.services import ssm
+ param_name = value
+ resolved_value = ssm.resolve_parameter_value(param_name)
+ if resolved_value is None:
+ raise ValueError(
+ f"Parameter '{name}' failed to resolve: SSM parameter "
+ f"'{param_name}' does not exist"
+ )
+ value = resolved_value
+
# Validate AllowedValues
allowed = defn.get("AllowedValues")
if allowed and value not in [str(a) for a in allowed]:
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index aef235be..7b9e6e87 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -470,6 +470,116 @@ def test_cfn_stack_with_parameters(cfn, sqs):
urls = sqs.list_queues(QueueNamePrefix="cfn-t02-custom").get("QueueUrls", [])
assert any("cfn-t02-custom" in u for u in urls)
+
+def test_cfn_ssm_parameter_value_type_resolves_stored_value(cfn, ssm, sqs):
+ """A `AWS::SSM::Parameter::Value<String>` template parameter's Default/
+ provided value is an SSM parameter *name*, not the value itself — real
+ CloudFormation resolves it against SSM Parameter Store before `Ref` ever
+ sees it (the mechanism behind CDK's `StringParameter.valueForStringParameter`).
+ Ref must yield the stored value, not the parameter name."""
+ ssm.put_parameter(Name="/cfn-t02c/queue-name", Value="cfn-t02c-resolved", Type="String")
+
+ template = {
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Parameters": {
+ "QueueName": {
+ "Type": "AWS::SSM::Parameter::Value<String>",
+ "Default": "/cfn-t02c/queue-name",
+ }
+ },
+ "Resources": {
+ "Queue": {
+ "Type": "AWS::SQS::Queue",
+ "Properties": {"QueueName": {"Ref": "QueueName"}},
+ }
+ },
+ }
+ cfn.create_stack(StackName="cfn-t02c", TemplateBody=json.dumps(template))
+ _wait_stack(cfn, "cfn-t02c")
+
+ urls = sqs.list_queues(QueueNamePrefix="cfn-t02c-resolved").get("QueueUrls", [])
+ assert any("cfn-t02c-resolved" in u for u in urls)
+ # Never the literal parameter name — that would mean resolution silently
+ # fell back to treating the SSM path as the value itself.
+ urls_by_name = sqs.list_queues(QueueNamePrefix="cfn-t02c/queue-name").get("QueueUrls", [])
+ assert urls_by_name == []
+
+
+def test_cfn_ssm_parameter_value_type_use_previous_value_on_update(cfn, ssm, sqs):
+ """A change set that re-sends an AWS::SSM::Parameter::Value<String>
+ parameter as UsePreviousValue (the `aws cloudformation deploy`
+ no-`--parameter-overrides` path, and what CDK sends for parameters it
+ isn't touching, e.g. its own BootstrapVersion) must reuse the
+ already-resolved value from the prior deployment as-is — not feed that
+ resolved value back into another SSM lookup, where it would almost
+ never itself be a valid parameter name and the update would fail."""
+ ssm.put_parameter(Name="/cfn-t02e/queue-name", Value="cfn-t02e-resolved", Type="String")
+
+ def template(bucket_tag):
+ return json.dumps({
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Parameters": {
+ "QueueName": {
+ "Type": "AWS::SSM::Parameter::Value<String>",
+ "Default": "/cfn-t02e/queue-name",
+ },
+ "Tag": {"Type": "String", "Default": bucket_tag},
+ },
+ "Resources": {
+ "Queue": {
+ "Type": "AWS::SQS::Queue",
+ "Properties": {
+ "QueueName": {"Ref": "QueueName"},
+ "Tags": [{"Key": "build", "Value": {"Ref": "Tag"}}],
+ },
+ }
+ },
+ })
+
+ cfn.create_stack(StackName="cfn-t02e", TemplateBody=template("v1"))
+ _wait_stack(cfn, "cfn-t02e")
+
+ # Second deploy changes an unrelated parameter (Tag) and re-sends
+ # QueueName as UsePreviousValue, exactly as CDK does for parameters it
+ # isn't updating this deploy.
+ cfn.create_change_set(
+ StackName="cfn-t02e", ChangeSetName="cs2", TemplateBody=template("v2"),
+ Parameters=[{"ParameterKey": "QueueName", "UsePreviousValue": True}],
+ )
+ cfn.execute_change_set(StackName="cfn-t02e", ChangeSetName="cs2")
+ stack = _wait_stack(cfn, "cfn-t02e")
+ assert stack["StackStatus"] == "UPDATE_COMPLETE"
+
+ urls = sqs.list_queues(QueueNamePrefix="cfn-t02e-resolved").get("QueueUrls", [])
+ assert any("cfn-t02e-resolved" in u for u in urls)
+
+
+def test_cfn_ssm_parameter_value_type_missing_parameter_fails_stack(cfn):
+ """An `AWS::SSM::Parameter::Value<String>` naming a parameter that was
+ never put must fail the same way real CloudFormation does — a
+ synchronous ValidationError at CreateStack time (parameter resolution
+ happens before the stack is created), not a silent resolve to the
+ parameter's own name string."""
+ template = {
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Parameters": {
+ "QueueName": {
+ "Type": "AWS::SSM::Parameter::Value<String>",
+ "Default": "/cfn-t02d/does-not-exist",
+ }
+ },
+ "Resources": {
+ "Queue": {
+ "Type": "AWS::SQS::Queue",
+ "Properties": {"QueueName": {"Ref": "QueueName"}},
+ }
+ },
+ }
+ with pytest.raises(ClientError) as exc_info:
+ cfn.create_stack(StackName="cfn-t02d", TemplateBody=json.dumps(template))
+ assert exc_info.value.response["Error"]["Code"] == "ValidationError"
+
+
def test_cfn_change_set_use_previous_value_updates_resource(cfn, ssm):
"""A change set created with UsePreviousValue (the `aws cloudformation deploy`
no-`--parameter-overrides` path) must resolve the parameter to its stored