Skip to content

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

feat(cfn): support API Gateway domain names (#1151)

robert-pitt-foodhub7994ce6d58b0
diff --git a/README.md b/README.md
index a44b4360..b0c57059 100644
--- a/README.md
+++ b/README.md
@@ -490,6 +490,7 @@ subnet = ec2.create_subnet(
| `AWS::ApiGateway::Model` | Model name | — |
| `AWS::ApiGateway::Deployment` | Deployment ID | — |
| `AWS::ApiGateway::Stage` | Stage name | — |
+| `AWS::ApiGateway::DomainName` | Domain name | DistributionDomainName, DistributionHostedZoneId, DomainNameArn, RegionalDomainName, RegionalHostedZoneId |
| `AWS::ApiGateway::GatewayResponse` | Response ID | Id |
| `AWS::AppConfig::Application` | Application ID | ApplicationId |
| `AWS::AppSync::GraphQLApi` | API ID | Arn, GraphQLUrl, ApiId |
diff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.py
index 8f79cdd5..6fbf348d 100644
--- a/ministack/services/apigateway_v1.py
+++ b/ministack/services/apigateway_v1.py
@@ -2244,10 +2244,17 @@ def _create_domain_name(data):
"domainName": domain_name,
"certificateName": data.get("certificateName", ""),
"certificateArn": data.get("certificateArn", ""),
+ "regionalCertificateName": data.get("regionalCertificateName", ""),
+ "regionalCertificateArn": data.get("regionalCertificateArn", ""),
"distributionDomainName": f"{domain_name}.cloudfront.net",
+ "distributionHostedZoneId": "Z2FDTNDATAQYW2",
"regionalDomainName": f"{domain_name}.execute-api.{get_region()}.amazonaws.com",
"regionalHostedZoneId": "Z1UJRXOUMOOFQ8",
"endpointConfiguration": data.get("endpointConfiguration", {"types": ["REGIONAL"]}),
+ "endpointAccessMode": data.get("endpointAccessMode", ""),
+ "mutualTlsAuthentication": data.get("mutualTlsAuthentication", {}),
+ "ownershipVerificationCertificateArn": data.get("ownershipVerificationCertificateArn", ""),
+ "routingMode": data.get("routingMode", "BASE_PATH_MAPPING_ONLY"),
# securityPolicy is an opaque enum at the wire level; AWS keeps adding
# new values (e.g. SecurityPolicy-TLS13-1-2-FIPS-PFS-PQ-2025-09 in
# 2026-03). Accept whatever the caller sends; default mirrors AWS.
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index f320f3a7..f06306f6 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -2112,6 +2112,80 @@ def _apigw_account_delete(physical_id, props):
_apigw_v1._account_settings["settings"] = settings
+# --- API Gateway DomainName ---
+
+def _apigw_domain_name_create(logical_id, props, stack_name):
+ """Provision an ``AWS::ApiGateway::DomainName`` through API Gateway v1."""
+ endpoint = props.get("EndpointConfiguration") or {}
+ endpoint_configuration = {
+ "types": endpoint.get("Types", ["REGIONAL"]),
+ }
+ if "IpAddressType" in endpoint:
+ endpoint_configuration["ipAddressType"] = endpoint["IpAddressType"]
+ if "VpcEndpointIds" in endpoint:
+ endpoint_configuration["vpcEndpointIds"] = endpoint["VpcEndpointIds"]
+
+ mutual_tls = props.get("MutualTlsAuthentication") or {}
+ mutual_tls_configuration = {}
+ if "TruststoreUri" in mutual_tls:
+ mutual_tls_configuration["truststoreUri"] = mutual_tls["TruststoreUri"]
+ if "TruststoreVersion" in mutual_tls:
+ mutual_tls_configuration["truststoreVersion"] = mutual_tls["TruststoreVersion"]
+
+ data = {
+ "domainName": props.get("DomainName", ""),
+ "endpointConfiguration": endpoint_configuration,
+ "tags": {tag["Key"]: tag["Value"] for tag in props.get("Tags", [])},
+ }
+ property_map = {
+ "CertificateArn": "certificateArn",
+ "EndpointAccessMode": "endpointAccessMode",
+ "OwnershipVerificationCertificateArn": "ownershipVerificationCertificateArn",
+ "RegionalCertificateArn": "regionalCertificateArn",
+ "RoutingMode": "routingMode",
+ "SecurityPolicy": "securityPolicy",
+ }
+ for cfn_name, api_name in property_map.items():
+ if cfn_name in props:
+ data[api_name] = props[cfn_name]
+ if mutual_tls_configuration:
+ data["mutualTlsAuthentication"] = mutual_tls_configuration
+
+ status, _headers, body = _apigw_v1._create_domain_name(data)
+ if status >= 400:
+ raise ValueError(f"AWS::ApiGateway::DomainName create failed: {body!r}")
+ domain = json.loads(body)
+ domain_name = domain["domainName"]
+ attrs = {
+ "DistributionDomainName": domain["distributionDomainName"],
+ "DistributionHostedZoneId": domain["distributionHostedZoneId"],
+ "DomainNameArn": f"arn:aws:apigateway:{get_region()}::/domainnames/{domain_name}",
+ "RegionalDomainName": domain["regionalDomainName"],
+ "RegionalHostedZoneId": domain["regionalHostedZoneId"],
+ }
+ return domain_name, attrs
+
+
+def _apigw_domain_name_update(physical_id, old_props, new_props, stack_name):
+ existing_mappings = _apigw_v1._base_path_mappings.get(physical_id)
+ new_domain_name = new_props.get("DomainName", "")
+ new_id, attrs = _apigw_domain_name_create(physical_id, new_props, stack_name)
+ if new_domain_name != physical_id:
+ _apigw_domain_name_delete(physical_id, old_props)
+ elif existing_mappings is not None:
+ # The native create helper initializes this collection. Preserve
+ # dependent mappings while mutable domain properties update in place.
+ _apigw_v1._base_path_mappings[physical_id] = existing_mappings
+ return new_id, attrs
+
+
+def _apigw_domain_name_delete(physical_id, props):
+ # Rollback and repeated stack deletion should remain harmless when the
+ # underlying custom domain has already been removed.
+ if physical_id in _apigw_v1._domain_names:
+ _apigw_v1._delete_domain_name(physical_id)
+
+
# --- API Gateway GatewayResponse ---
def _apigw_gateway_response_create(logical_id, props, stack_name):
@@ -4820,6 +4894,11 @@ _RESOURCE_HANDLERS = {
"AWS::ApiGateway::Deployment": {"create": _apigw_deployment_create, "delete": _apigw_deployment_delete},
"AWS::ApiGateway::Stage": {"create": _apigw_stage_create, "delete": _apigw_stage_delete},
"AWS::ApiGateway::Account": {"create": _apigw_account_create, "delete": _apigw_account_delete},
+ "AWS::ApiGateway::DomainName": {
+ "create": _apigw_domain_name_create,
+ "update": _apigw_domain_name_update,
+ "delete": _apigw_domain_name_delete,
+ },
"AWS::ApiGateway::GatewayResponse": {
"create": _apigw_gateway_response_create,
"update": _apigw_gateway_response_update,
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index 5f1075bc..85fc6cc6 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -4189,6 +4189,93 @@ def test_cfn_apigateway_account_provisions(cfn, apigw_v1):
_wait_stack(cfn, stack_name)
+def test_cfn_apigateway_domain_name_lifecycle(cfn, apigw_v1):
+ """CloudFormation provisions CDK-style regional and edge custom domains."""
+ suffix = _uuid_mod.uuid4().hex[:8]
+ stack_name = f"intg-cfn-apigw-domain-{suffix}"
+ regional_name = f"regional-{suffix}.example.local"
+ edge_name = f"edge-{suffix}.example.local"
+ regional_certificate_arn = (
+ f"arn:aws:acm:us-east-1:000000000000:certificate/regional-{suffix}"
+ )
+ edge_certificate_arn = (
+ f"arn:aws:acm:us-east-1:000000000000:certificate/edge-{suffix}"
+ )
+ template = {
+ "Resources": {
+ "RegionalDomain": {
+ "Type": "AWS::ApiGateway::DomainName",
+ "Properties": {
+ "DomainName": regional_name,
+ "EndpointConfiguration": {"Types": ["REGIONAL"]},
+ "RegionalCertificateArn": regional_certificate_arn,
+ "SecurityPolicy": "TLS_1_2",
+ "Tags": [{"Key": "created-by", "Value": "cloudformation"}],
+ },
+ },
+ "EdgeDomain": {
+ "Type": "AWS::ApiGateway::DomainName",
+ "Properties": {
+ "DomainName": edge_name,
+ "EndpointConfiguration": {"Types": ["EDGE"]},
+ "CertificateArn": edge_certificate_arn,
+ "SecurityPolicy": "TLS_1_2",
+ },
+ },
+ },
+ "Outputs": {
+ "RegionalRef": {"Value": {"Ref": "RegionalDomain"}},
+ "RegionalDomainName": {
+ "Value": {"Fn::GetAtt": ["RegionalDomain", "RegionalDomainName"]},
+ },
+ "RegionalHostedZoneId": {
+ "Value": {"Fn::GetAtt": ["RegionalDomain", "RegionalHostedZoneId"]},
+ },
+ "RegionalDomainNameArn": {
+ "Value": {"Fn::GetAtt": ["RegionalDomain", "DomainNameArn"]},
+ },
+ "DistributionDomainName": {
+ "Value": {"Fn::GetAtt": ["EdgeDomain", "DistributionDomainName"]},
+ },
+ "DistributionHostedZoneId": {
+ "Value": {"Fn::GetAtt": ["EdgeDomain", "DistributionHostedZoneId"]},
+ },
+ },
+ }
+
+ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template))
+ stack = _wait_stack(cfn, stack_name)
+ assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")
+
+ outputs = {item["OutputKey"]: item["OutputValue"] for item in stack.get("Outputs", [])}
+ assert outputs["RegionalRef"] == regional_name
+ assert outputs["RegionalDomainName"] == (
+ f"{regional_name}.execute-api.us-east-1.amazonaws.com"
+ )
+ assert outputs["RegionalHostedZoneId"] == "Z1UJRXOUMOOFQ8"
+ assert outputs["RegionalDomainNameArn"] == (
+ f"arn:aws:apigateway:us-east-1::/domainnames/{regional_name}"
+ )
+ assert outputs["DistributionDomainName"] == f"{edge_name}.cloudfront.net"
+ assert outputs["DistributionHostedZoneId"] == "Z2FDTNDATAQYW2"
+
+ regional = apigw_v1.get_domain_name(domainName=regional_name)
+ assert regional["endpointConfiguration"] == {"types": ["REGIONAL"]}
+ assert regional["regionalCertificateArn"] == regional_certificate_arn
+ assert regional["tags"] == {"created-by": "cloudformation"}
+ edge = apigw_v1.get_domain_name(domainName=edge_name)
+ assert edge["endpointConfiguration"] == {"types": ["EDGE"]}
+ assert edge["certificateArn"] == edge_certificate_arn
+
+ cfn.delete_stack(StackName=stack_name)
+ deleted = _wait_stack(cfn, stack_name)
+ assert deleted["StackStatus"] == "DELETE_COMPLETE"
+ for domain_name in (regional_name, edge_name):
+ with pytest.raises(ClientError) as exc:
+ apigw_v1.get_domain_name(domainName=domain_name)
+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404
+
+
def test_cfn_apigateway_gateway_response_resolves_rest_api_ref(cfn, apigw_v1):
"""The issue #1124 CDK shape provisions a response against a stack REST API."""
suffix = _uuid_mod.uuid4().hex[:8]