Skip to content

HttpApi: v2.234.0 broke DomainNameMapping behavior #36708

@jar-of-salt

Description

@jar-of-salt

Describe the bug

When using an imported DomainName, we encounter a deployment issue with the following error:

Resource handler returned message: "Invalid domain name identifier specified (Service: AmazonApiGatewayV2; Status Code: 404; Error Code: NotFoundException; Request ID: {...}; Proxy: null)

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

v2.233.0

Expected Behavior

HttpApi deploys successfully with imported DomainName

Current Behavior

HttpApi fails to deploy with imported DomainName, fails with a NotFoundException

Reproduction Steps

Import a custom domain name, then try to use it on an HttpApi:

domain_name = aws_http_api.DomainName.from_domain_name_attributes(
    scope, "api-domain-name",
    name="<DOMAIN NAME STRING>",
    regional_domain_name="<REGIONAL DOMAIN NAME>",
    regional_hosted_zone_id="<HOSTED ZONE ID FROM DOMAIN NAME>")

http_api = aws_http_api.HttpApi(
    scope, "http-api",
    default_domain_mapping=aws_http_api.DomainMappingOptions(
    domain_name=domain_name, 
    mapping_key=settings.base_route)
    )

Possible Solution

The CDK-side cause appears to be the regionalDomainName (the randomly generated value {random identifier for domain name}.execute-api.{region}.amazonaws.com) being substituted value in the DomainName property of AWS::ApiGatewayV2::ApiMapping. This behavior causes the deployment to fail because no DomainName with that name exists, since those (regionalDomainName) identifiers appear to be purely internal.

The root cause appears to be the interplay of the following:

  • fromDomainNameAttributes: The DomainNameReference created as the imported value is malformed.
  • When the ApiMapping actually gets created by StageBase
    • const apiMappingProps: CfnApiMappingProps = {
      apiId: props.api.apiRef.apiId,
      domainName: props.domainName.domainNameRef.domainName,
      stage: stage.stageName,
      apiMappingKey: props.apiMappingKey,
      };
    • It uses the domainNameRef.domainName which is the regionalDomainName instead of the non-random (for example)some.domain.name.com

TLDR;
DomainNameReference in fromDomainNameAttributes here needs to be the following

public readonly domainNameRef: DomainNameReference = {
    domainName: attrs.name,  // <-- HERE
    domainNameArn: Stack.of(this).formatArn({
      service: 'apigateway',
      arnFormat: ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME,
      resource: 'domainnames',
      resourceName: attrs.regionalDomainName,
    }),
  };
}

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

v2.235.0

AWS CDK CLI version

2.1100.1

Node.js Version

22

OS

Ubuntu - LTS

Language

Python

Language Version

Python 3.12

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-apigatewayv2Related to Amazon API Gateway v2bugThis issue is a bug.p0potential-regressionMarking this issue as a potential regression to be checked by team memberresponse-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions