Repository navigation
fix(ts#api,py#api): publish the custom domain URL in runtime config - #1278
Merged
shsrams merged 5 commits intoOct 3, 2026
Merged
Conversation
When an API is given a custom domain, runtime config now publishes the custom domain URL instead of the generated execute-api endpoint. - CDK RestApi publishes https://<domainName>/[<basePath>/] when domainName is set. - CDK HttpApi forwards defaultDomainMapping to the stage it creates (CDK rejected it while the default stage is disabled), typed with an IDomainName, and publishes the mapping's domain URL. - Both output the custom domain's DNS record target (regional domain name and hosted zone ID). - The Terraform REST and HTTP API modules gain optional custom_domain_name and acm_certificate_arn variables, the domain and mapping resources, an api_url local published in runtime config, and api_url / DNS target outputs. - The api-custom-domain-runtime-config migration brings existing vended constructs and modules to the generated shape, skipping and reporting anything customised. - The API guides gain a Custom domain section.
… and getter Addresses PR review feedback: - HttpApi computes its URL once (the custom domain's when one is mapped) and uses it for the <apiName>Url stack output, runtime config and the url getter; the migration rewrites all three. - The e2e Terraform plan test plans the REST and HTTP API modules with a custom domain and asserts the published api_url. - Terraform: a plan-time precondition requires acm_certificate_arn when custom_domain_name is set; the HTTP mapping references the domain name; api_url sits with the module's other locals. - Sorted imports, an endpoint-neutral REST DNS output description, and docs noting basePath is CDK-only and TLS 1.2 is the default.
Contributor
Author
|
@shsrams thanks for the thorough review. All addressed in ec96fce and 82e41f2: Blocking
Suggestions: all applied.
The translations came from |
shsrams
self-requested a review
October 2, 2026 19:27
shsrams
approved these changes
Oct 2, 2026
shsrams
left a comment
Collaborator
There was a problem hiding this comment.
All comments addressed. Thanks Alex!!
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1278 +/- ##
==========================================
+ Coverage 89.06% 89.13% +0.06%
==========================================
Files 291 292 +1
Lines 12586 12698 +112
Branches 3052 3073 +21
==========================================
+ Hits 11210 11318 +108
- Misses 554 555 +1
- Partials 822 825 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for this change
When an API is given a custom domain, the vended constructs still publish the generated
execute-apiURL in runtime config, so websites and other clients keep calling the AWS endpoint instead of the custom domain. There is also no easy way to find the target for the domain's DNS record.RestApi:domainNameis passed through to API Gateway, but runtime config always receivesthis.api.url(which also carries the/prod/stage prefix the custom domain doesn't use).HttpApi: passingdefaultDomainMappingthrows, because the construct setscreateDefaultStage: falseand CDK only applies that prop to the default stage it creates.Description of changes
CDK (
common/constructs/src/core/api)RestApidestructuresdomainName, passes it to the CDKRestApi, and publisheshttps://<domainName>/(plus<basePath>/if set) in runtime config when it is configured, otherwise the execute-api URL as before.HttpApitakesdefaultDomainMappingout of the props passed to the CDKHttpApiand passes it asdomainMappingto the stage it creates, then uses the stage'sdomainUrlfor runtime config, the<apiName>Urlstack output and the construct'surlgetter. The prop keeps CDK's name, but is typed with anIDomainNameso its regional attributes are available (CDK types it as the narrowerIDomainNameRef).<apiName>DomainNameAlias, the domain name to point a CNAME at with any DNS provider, and<apiName>DomainNameAliasHostedZoneId, needed only for a Route 53 alias record.Terraform (
common/terraform/src/app/apis/<name>/<name>.tf, REST and HTTP)custom_domain_nameandacm_certificate_arnvariables (named to match the static website module).custom_domain_namewithoutacm_certificate_arnfails at plan time.api_urllocal is published in runtime config: the custom domain URL when configured, otherwise the stage invoke URL as before.api_url, pluscustom_domain_target_domain_nameandcustom_domain_hosted_zone_idfor the DNS record.With no custom domain configured, runtime config and the deployed resources are unchanged.
Docs
api/custom-domainsnippet, included as a "Custom domain" section in the tRPC, FastAPI and Smithy API guides: configuring the domain and certificate in CDK (REST and HTTP) and Terraform, the runtime configuration URL, and creating the DNS record with any provider (CNAME) or Route 53 (alias).api_urloutput, which reflects a configured custom domain.Migration (
latest/api-custom-domain-runtime-config, deterministic)These files are vended with
KeepExisting, so existing workspaces need a migration to reach the generated shape. It rewrites the vended CDK constructs and each Terraform API app module with GritQL, and a migrated file matches a freshly generated one exactly. It is conservative about what it touches:_HttpApiPropsbase of theHttpApiPropsinterface is replaced, keeping any other base interfaces, and an unrelatedCfnOutputalready in the construct doesn't block it./v1/suffix) is left alone..tffile in the module directory for the names it adds, since Terraform merges them. Any collision, or a partial/custom configuration already in place, leaves the module untouched.nextStepswith what to reconcile by hand. A re-run is a no-op.On the infrastructure transition: the only resources added are the domain and mapping, and only when a custom domain is configured, so migrating and redeploying an existing stack without one changes nothing but the new Terraform outputs.
Description of how you validated changes
throttle, extra base interfaces onHttpApiProps, an existing unrelatedCfnOutput, an existing DNS alias output, a customised REST URL, the HTTP construct'surlgetter (rewritten, or reported when customised), and colliding or partial declarations in the same file and in sibling files. The guard tests were checked to fail against the earlier, looser guards.OptionFilterconditions validated against the guides' generator schemas.terraform testnow also plans the generated REST and HTTP API modules with a custom domain and asserts each publishes the custom domain URL asapi_url.@aws/nx-plugin@1.0.3, each with a tRPC REST and HTTP API, then upgraded to a locally packed build and migrated withnx migrate --run-migrations:nextSteps, and a re-run made no changes;aws-cdk-lib2.270 and CDK synth, and checkov with 0 failed checks on Terraform;https://rest.example.com/v1/and the HTTP domain URL into the AppConfig runtime config, theDomainNameand mapping resources, and the four DNS alias outputs (RegionalDomainName/RegionalHostedZoneId); the HTTP API'sHttpApiUrloutput andurlgetter resolve to the custom domain URL too;custom_domain_nameset, readingapi_urland the DNS target outputs, passesterraform validateand a mocked-provider plan asserting bothapi_urls, the plan fails with a clear message whenacm_certificate_arnis missing, and the migration's lines areterraform fmtclean;locals.tfdeclaringapi_url, the HTTP module was left untouched and reported, and the REST module migrated.Issue # (if applicable)
N/A
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license