Skip to content

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

fix(cloudformation): GetTemplateSummary now returns capabilities info (#913)

maximoosemine153679c62fca
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a768da9..51b4de78 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **CloudFormation — `GetTemplateSummary` now returns `Capabilities` and `CapabilitiesReason`** — the handler already accepted `TemplateBody` and returned `Parameters` / `ResourceTypes` correctly, but omitted the `Capabilities` and `CapabilitiesReason` fields. These are now computed from the template: `CAPABILITY_NAMED_IAM` for IAM resources with explicit name properties (`RoleName`, `UserName`, etc.), `CAPABILITY_IAM` for unnamed IAM resources, and `CAPABILITY_AUTO_EXPAND` for templates with a `Transform`. `CapabilitiesReason` uses the format confirmed against the AWS API: `"The following resource(s) require capabilities: [<type>]"`. Contributed by @maximoosemine.
- **Lambda - CreateEventSourceMapping persists FilterCriteria** — CreateEventSourceMapping was silently dropping the FilterCriteria parameter, so any filter specified at creation time was never applied.
- **ECS — `RunTask` now applies `containerOverrides.command` to the launched Docker container** — Overridden commands (including an explicit empty command) were ignored at runtime because the Docker `containers.run(...)` call still used the task-definition command. The effective container definition now carries the matched override command into Docker, while non-overridden containers keep their defaults.
diff --git a/ministack/services/cloudformation/handlers.py b/ministack/services/cloudformation/handlers.py
index 1d808b74..d0b2762a 100644
--- a/ministack/services/cloudformation/handlers.py
+++ b/ministack/services/cloudformation/handlers.py
@@ -627,11 +627,61 @@ def _get_template_summary(params):
"</member>"
)
+ _NAMED_IAM_PROPS = {
+ "AWS::IAM::Role": "RoleName",
+ "AWS::IAM::User": "UserName",
+ "AWS::IAM::Group": "GroupName",
+ "AWS::IAM::Policy": "PolicyName",
+ "AWS::IAM::ManagedPolicy": "ManagedPolicyName",
+ "AWS::IAM::InstanceProfile": "InstanceProfileName",
+ }
+ named_iam_ids = []
+ unnamed_iam_ids = []
+ for logical_id, res in resources.items():
+ rtype = res.get("Type", "")
+ if not rtype.startswith("AWS::IAM::"):
+ continue
+ name_prop = _NAMED_IAM_PROPS.get(rtype)
+ if name_prop and res.get("Properties", {}).get(name_prop):
+ named_iam_ids.append(logical_id)
+ else:
+ unnamed_iam_ids.append(logical_id)
+
+ capabilities = []
+ caps_reason_types = []
+ if named_iam_ids:
+ capabilities.append("CAPABILITY_NAMED_IAM")
+ caps_reason_types.extend(
+ sorted(set(resources[lid].get("Type", "") for lid in named_iam_ids))
+ )
+ elif unnamed_iam_ids:
+ capabilities.append("CAPABILITY_IAM")
+ caps_reason_types.extend(
+ sorted(set(resources[lid].get("Type", "") for lid in unnamed_iam_ids))
+ )
+ if template.get("Transform"):
+ capabilities.append("CAPABILITY_AUTO_EXPAND")
+
+ caps_xml = "".join(f"<member>{c}</member>" for c in capabilities)
+ # AWS'es behavior here is very inconsistent with their docs. AWS doesn't necessarily return
+ # all of the types it should every time. We're doing the best we can here.
+ caps_reason = (
+ "The following resource(s) require capabilities: [" + ", ".join(caps_reason_types) + "]"
+ if caps_reason_types else ""
+ )
+
+ caps_block = (
+ f"<Capabilities>{caps_xml}</Capabilities>"
+ f"<CapabilitiesReason>{_esc(caps_reason)}</CapabilitiesReason>"
+ if capabilities else ""
+ )
+
return _xml(200, "GetTemplateSummaryResponse",
f"<GetTemplateSummaryResult>"
f"<Description>{_esc(description)}</Description>"
f"<ResourceTypes>{types_xml}</ResourceTypes>"
f"<Parameters>{params_xml}</Parameters>"
+ f"{caps_block}"
f"</GetTemplateSummaryResult>")
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index d203a77a..8e419053 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -463,6 +463,67 @@ def test_cfn_validate_template(cfn):
with pytest.raises(ClientError):
cfn.validate_template(TemplateBody=json.dumps(invalid_template))
+def test_cfn_get_template_summary(cfn):
+ # Basic template: parameters and resource types surfaced, no capabilities
+ basic = {
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Description": "summary test",
+ "Parameters": {
+ "Env": {"Type": "String", "Default": "dev", "Description": "env"},
+ },
+ "Resources": {
+ "Bucket": {"Type": "AWS::S3::Bucket"},
+ },
+ }
+ result = cfn.get_template_summary(TemplateBody=json.dumps(basic))
+ assert result["Description"] == "summary test"
+ assert "AWS::S3::Bucket" in result["ResourceTypes"]
+ assert any(p["ParameterKey"] == "Env" for p in result["Parameters"])
+ assert result.get("Capabilities", []) == []
+
+ # IAM role with explicit RoleName → CAPABILITY_NAMED_IAM
+ named_iam = {
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Resources": {
+ "Role": {
+ "Type": "AWS::IAM::Role",
+ "Properties": {
+ "RoleName": "my-role",
+ "AssumeRolePolicyDocument": {"Version": "2012-10-17", "Statement": []},
+ },
+ }
+ },
+ }
+ result = cfn.get_template_summary(TemplateBody=json.dumps(named_iam))
+ assert "CAPABILITY_NAMED_IAM" in result["Capabilities"]
+ assert result.get("CapabilitiesReason") == "The following resource(s) require capabilities: [AWS::IAM::Role]"
+
+ # IAM role without explicit name → CAPABILITY_IAM
+ unnamed_iam = {
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Resources": {
+ "Role": {
+ "Type": "AWS::IAM::Role",
+ "Properties": {
+ "AssumeRolePolicyDocument": {"Version": "2012-10-17", "Statement": []},
+ },
+ }
+ },
+ }
+ result = cfn.get_template_summary(TemplateBody=json.dumps(unnamed_iam))
+ assert result["Capabilities"] == ["CAPABILITY_IAM"]
+
+ # Template with Transform → CAPABILITY_AUTO_EXPAND
+ transform_tpl = {
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Transform": "AWS::Serverless-2016-10-31",
+ "Resources": {
+ "Fn": {"Type": "AWS::Serverless::Function", "Properties": {}},
+ },
+ }
+ result = cfn.get_template_summary(TemplateBody=json.dumps(transform_tpl))
+ assert "CAPABILITY_AUTO_EXPAND" in result["Capabilities"]
+
def test_cfn_list_stacks(cfn):
for name in ("cfn-t12-a", "cfn-t12-b"):
template = {