-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
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: TheDomainNameReferencecreated as the imported value is malformed.aws-cdk/packages/aws-cdk-lib/aws-apigatewayv2/lib/common/domain-name.ts
Lines 182 to 190 in d929ef7
public readonly domainNameRef: DomainNameReference = { domainName: attrs.regionalDomainName, domainNameArn: Stack.of(this).formatArn({ service: 'apigateway', arnFormat: ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME, resource: 'domainnames', resourceName: attrs.regionalDomainName, }), }; - it uses the
regionalDomainNameinstead of thenamefrom DomainNameAttributes
- When the
ApiMappingactually gets created byStageBaseaws-cdk/packages/aws-cdk-lib/aws-apigatewayv2/lib/common/api-mapping.ts
Lines 133 to 138 in f9f6f90
const apiMappingProps: CfnApiMappingProps = { apiId: props.api.apiRef.apiId, domainName: props.domainName.domainNameRef.domainName, stage: stage.stageName, apiMappingKey: props.apiMappingKey, }; - It uses the
domainNameRef.domainNamewhich is theregionalDomainNameinstead 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