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
Support CloudWatch dashboards in CloudFormation (#1156)
robert-pitt-foodhub2402636ffd43
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9cfeab40..05d94c36 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]### Added+- **CloudWatch — `AWS::CloudWatch::Dashboard` CloudFormation support** — stacks containing CloudWatch dashboards no longer roll back with `Unsupported resource type`. Dashboard creation, in-place body updates, name replacement, `Ref`, and deletion now use the existing CloudWatch dashboard store. Fixes #1155.- **Cognito — resource servers** (`CreateResourceServer`, `UpdateResourceServer`, `DescribeResourceServer`, `DeleteResourceServer`, `ListResourceServers`) plus `AWS::Cognito::UserPoolResourceServer` CloudFormation support. Previously every resource-server action returned `InvalidAction: Unknown Cognito IDP action`, and the CFN resource type failed the whole stack with `Unsupported resource type`, so any app pool defining custom OAuth scopes (`{identifier}/{scopeName}`, e.g. for `HttpJwtAuthorizer` `authorizationScopes` gating on API Gateway) couldn't deploy against MiniStack at all. Resource servers are keyed by their caller-supplied `Identifier` within a pool, matching real AWS, and `Ref` on the CFN resource returns that `Identifier`. Contributed by @ryan-bennett.## [1.4.4] — 2026-07-22diff --git a/README.md b/README.mdindex b0c57059..6b7bc760 100644--- a/README.md+++ b/README.md@@ -534,6 +534,7 @@ subnet = ec2.create_subnet(| `AWS::WAFv2::WebACL` | WebACL ID | Arn, Id || `AWS::CloudFront::Distribution` | Distribution ID | Arn, DomainName, Id || `AWS::CloudWatch::Alarm` | Alarm name | Arn |+| `AWS::CloudWatch::Dashboard` | Dashboard name | — || `AWS::RDS::DBCluster` | Cluster ID | Arn, Endpoint.Address, Endpoint.Port, ReadEndpoint.Address || `AWS::AutoScaling::AutoScalingGroup` | ASG name | Arn || `AWS::AutoScaling::LaunchConfiguration` | LC name | Arn |diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex 19108af3..2d1d3a40 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -4108,6 +4108,50 @@ def _cw_metric_alarm_delete(physical_id, props):_cw.cloudformation_delete_metric_alarm(physical_id)+# ---------------------------------------------------------------------------+# CloudWatch Dashboard+# ---------------------------------------------------------------------------+++def _cw_dashboard_name(logical_id, props, stack_name):+ name = props.get("DashboardName") or _physical_name(+ stack_name, logical_id, max_len=255+ )+ if not isinstance(name, str) or not 1 <= len(name) <= 255:+ raise ValueError("DashboardName must be between 1 and 255 characters")+ return name+++def _cw_dashboard_body(props):+ body = props.get("DashboardBody")+ if not isinstance(body, str) or not body:+ raise ValueError("DashboardBody is required for AWS::CloudWatch::Dashboard")+ return body+++def _cw_dashboard_create(logical_id, props, stack_name):+ name = _cw_dashboard_name(logical_id, props, stack_name)+ _cw.cloudformation_put_dashboard(name, _cw_dashboard_body(props))+ return name, {}+++def _cw_dashboard_update(physical_id, old_props, new_props, stack_name):+ # DashboardBody updates happen in place. DashboardName changes require+ # replacement, which we model by creating the new dashboard before+ # deleting the previous physical resource.+ name = new_props.get("DashboardName") or physical_id+ if not isinstance(name, str) or not 1 <= len(name) <= 255:+ raise ValueError("DashboardName must be between 1 and 255 characters")+ _cw.cloudformation_put_dashboard(name, _cw_dashboard_body(new_props))+ if name != physical_id:+ _cw.cloudformation_delete_dashboard(physical_id)+ return name, {}+++def _cw_dashboard_delete(physical_id, props):+ _cw.cloudformation_delete_dashboard(physical_id)++# ---------------------------------------------------------------------------# ApiGatewayV2 Api# ---------------------------------------------------------------------------@@ -5009,6 +5053,11 @@ _RESOURCE_HANDLERS = {"AWS::CloudFront::Distribution": {"create": _cf_distribution_create, "delete": _cf_distribution_delete},"AWS::CloudFront::KeyValueStore": {"create": _cf_kvs_create, "update": _cf_kvs_update, "delete": _cf_kvs_delete},"AWS::CloudWatch::Alarm": {"create": _cw_metric_alarm_create, "delete": _cw_metric_alarm_delete},+ "AWS::CloudWatch::Dashboard": {+ "create": _cw_dashboard_create,+ "update": _cw_dashboard_update,+ "delete": _cw_dashboard_delete,+ },"AWS::RDS::DBCluster": {"create": _rds_db_cluster_create, "delete": _rds_db_cluster_delete},"AWS::RDS::DBInstance": {"create": _rds_db_instance_create, "delete": _rds_db_instance_delete},"AWS::IoT::TopicRule": {"create": _iot_topic_rule_create, "delete": _iot_topic_rule_delete},diff --git a/ministack/services/cloudwatch.py b/ministack/services/cloudwatch.pyindex e9ccea65..5d771e15 100644--- a/ministack/services/cloudwatch.py+++ b/ministack/services/cloudwatch.py@@ -1401,13 +1401,7 @@ def _put_dashboard(params, cbor_data, is_cbor, is_json=False):use_json=is_json, use_cbor=is_cbor,)- _dashboards[name] = {- "DashboardName": name,- "DashboardBody": body,- "DashboardArn": f"arn:aws:cloudwatch::{get_account_id()}:dashboard/{name}",- "LastModified": int(time.time()),- "Size": len(body),- }+ cloudformation_put_dashboard(name, body)if is_cbor:return _cbor_ok({"DashboardValidationMessages": []})@@ -1479,7 +1473,7 @@ def _delete_dashboards(params, cbor_data, is_cbor, is_json=False):404, use_json=is_json, use_cbor=is_cbor)for n in names:- _dashboards.pop(n, None)+ cloudformation_delete_dashboard(n)if is_cbor:return _cbor_ok({})@@ -1633,6 +1627,27 @@ def cloudformation_delete_metric_alarm(name: str) -> None:)+def cloudformation_put_dashboard(name: str, body: str) -> str:+ """Create or replace a dashboard from a CloudFormation resource."""+ arn = f"arn:aws:cloudwatch::{get_account_id()}:dashboard/{name}"+ _dashboards[name] = {+ "DashboardName": name,+ "DashboardBody": body,+ "DashboardArn": arn,+ "LastModified": int(time.time()),+ "Size": len(body),+ }+ return arn+++def cloudformation_delete_dashboard(name: str) -> None:+ """Remove a dashboard created from a CloudFormation resource."""+ _dashboards.pop(name, None)+ _resource_tags.pop(+ f"arn:aws:cloudwatch::{get_account_id()}:dashboard/{name}", None+ )++def reset():_alarms.clear()_composite_alarms.clear()diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 05884ab9..eec6382e 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -1963,6 +1963,62 @@ def test_cfn_cloudwatch_alarm_lifecycle(cfn, cw):assert resp2["MetricAlarms"] == []+def test_cfn_cloudwatch_dashboard_lifecycle(cfn, cw):+ """CloudFormation creates, updates, and removes a CloudWatch dashboard."""+ uid = _uuid_mod.uuid4().hex[:8]+ stack_name = f"cfn-cwdash-{uid}"+ dashboard_name = f"cfn-dashboard-{uid}"+ replacement_name = f"cfn-dashboard-replaced-{uid}"+ body = json.dumps({"widgets": [{"type": "text", "properties": {"markdown": "Created"}}]})+ updated_body = json.dumps({"widgets": [{"type": "text", "properties": {"markdown": "Updated"}}]})++ def template(dashboard_body, name=dashboard_name):+ return {+ "AWSTemplateFormatVersion": "2010-09-09",+ "Resources": {+ "Dashboard": {+ "Type": "AWS::CloudWatch::Dashboard",+ "Properties": {+ "DashboardName": name,+ "DashboardBody": dashboard_body,+ },+ },+ },+ "Outputs": {+ "DashboardName": {"Value": {"Ref": "Dashboard"}},+ },+ }++ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template(body)))+ stack = _wait_stack(cfn, stack_name)+ assert stack["StackStatus"] == "CREATE_COMPLETE"+ assert stack["Outputs"][0]["OutputValue"] == dashboard_name+ assert cw.get_dashboard(DashboardName=dashboard_name)["DashboardBody"] == body++ cfn.update_stack(StackName=stack_name, TemplateBody=json.dumps(template(updated_body)))+ stack = _wait_stack(cfn, stack_name)+ assert stack["StackStatus"] == "UPDATE_COMPLETE"+ assert cw.get_dashboard(DashboardName=dashboard_name)["DashboardBody"] == updated_body++ cfn.update_stack(+ StackName=stack_name,+ TemplateBody=json.dumps(template(updated_body, replacement_name)),+ )+ stack = _wait_stack(cfn, stack_name)+ assert stack["StackStatus"] == "UPDATE_COMPLETE"+ assert stack["Outputs"][0]["OutputValue"] == replacement_name+ with pytest.raises(ClientError) as exc:+ cw.get_dashboard(DashboardName=dashboard_name)+ assert exc.value.response["Error"]["Code"] == "ResourceNotFound"+ assert cw.get_dashboard(DashboardName=replacement_name)["DashboardBody"] == updated_body++ cfn.delete_stack(StackName=stack_name)+ _wait_stack(cfn, stack_name)+ with pytest.raises(ClientError) as exc:+ cw.get_dashboard(DashboardName=replacement_name)+ assert exc.value.response["Error"]["Code"] == "ResourceNotFound"++def test_cfn_route53_hosted_zone_and_record_set(cfn, r53):"""CloudFormation provisions Route53 HostedZone + RecordSet and removes records on delete."""uid = _uuid_mod.uuid4().hex[:8]