Add Route53 custom domain for App Runner demo#33
Conversation
Configure 10x-forms.labs.flexion.us DNS for the demo App Runner service, including hosted zone, custom domain association, certificate validation records, and CNAME to the service URL.
|
Code Review: Add Route53 custom domain for App Runner demoOverviewThis PR adds optional DNS provisioning to Issues & SuggestionsHard-coded loop count for certificate validation recordsfor (let i = 0; i < 3; i++) {This assumes App Runner will always return exactly 3 certificate validation CNAME records. In practice, the count depends on the domain and the issuing CA. If the number ever differs, the deployment will either create dangling records or — worse — silently miss a required validation record, causing certificate issuance to fail without an obvious error. Suggestion: Add a comment explaining why 3 is expected here (i.e., it's the observed behavior for App Runner with a single subdomain), or reference the AWS docs/source that guarantees this count. If the count is not guaranteed by the API contract, consider using a // App Runner issues certificates via ACM and provides exactly 3 CNAME validation
// records for a custom subdomain association. See AWS docs: <link>
const CERT_VALIDATION_RECORD_COUNT = 3;
for (let i = 0; i < CERT_VALIDATION_RECORD_COUNT; i++) {Raw Terraform escape-hatch strings bypass CDKTF type safetyname: `\${${customDomainAssociation.fqn}.certificate_validation_records[${i}].name}`,
type: `\${${customDomainAssociation.fqn}.certificate_validation_records[${i}].type}`,
records: [
`\${${customDomainAssociation.fqn}.certificate_validation_records[${i}].value}`,
],These escape-hatch strings ( Suggestion: Consider CNAME for subdomain apexnew Route53Record(this, `${id}-apprunner-alias`, {
...
name: domainName, // '10x-forms.labs.flexion.us'
type: 'CNAME',A CNAME at the zone apex is technically invalid per RFC 1912 and will be rejected by Route53. However, since Potential bug: Route53 will reject a CNAME at the zone apex. If
Missing
|
Provides Node.js 22, pnpm, Terraform, and native build tools (gcc, make, python3, pkg-config) needed for cdktf and node-gyp modules.
Code Review: Add Route53 custom domain for App Runner demoOverviewThis PR adds Route53 DNS and custom domain configuration for the demo App Runner service at Issues / Bugs1. Hardcoded certificate validation record count ( for (let i = 0; i < 3; i++) {The AWS App Runner A safer approach using CDKTF's // Use dynamic blocks via TerraformIterator if CDKTF supports it for this resource,
// or document that this assumption holds for single-hostname subdomainsAt minimum, add a comment documenting the assumption and a link to the AWS docs confirming the count. 2. Raw Terraform attribute interpolation is fragile ( name: `\${${customDomainAssociation.fqn}.certificate_validation_records[${i}].name}`,This bypasses CDKTF's type-safe attribute resolution in favour of raw string interpolation. If the FQN or attribute path ever changes (e.g., after a provider upgrade), this will silently produce invalid Terraform config that only fails at Potential Issues3. No Terraform infers dependencies from interpolated references, so the template string approach should work — but because it's raw string interpolation rather than a proper CDKTF reference, the dependency may not be registered. Consider adding explicit 4. The 5. CNAME on subdomain root — verify App Runner expectation App Runner typically expects an Nix / Dev Environment (
|
| Severity | Issue |
|---|---|
| Medium | Hardcoded i < 3 loop for validation records |
| Medium | Raw Terraform string interpolation bypasses type safety |
| Low | Missing explicit dependsOn on validation records |
| Low | No lifecycle config on ApprunnerCustomDomainAssociation |
| Nit | Node version in shell.nix may drift from .nvmrc |
The core logic is sound and the change is appropriately scoped. The main items to address before merging are the hardcoded validation record count and documenting (or replacing) the raw interpolation pattern.
The certificate validation records are only known after the App Runner custom domain association is created, so they cannot be managed as separate Terraform resources in a single apply. Instead, output them for manual DNS configuration after the initial deploy.
Code Review: Add Route53 custom domain for App Runner demoOverviewThis PR adds optional custom domain/DNS support to Issues🔴 CNAME at zone apex is a DNS violationFile: The Fix: Route53 supports Alias (A/AAAA) records at the zone apex for AWS services. If App Runner's // If an alias record is supported:
new Route53Record(this, `${id}-apprunner-alias`, {
zoneId: zone.zoneId,
name: domainName,
type: 'A',
alias: {
name: customDomainAssociation.dnsTarget,
zoneId: '<apprunner-hosted-zone-id>',
evaluateTargetHealth: true,
},
});🟡
|
Remove the CNAME record that would have been placed at the zone apex (10x-forms.labs.flexion.us), which is invalid per RFC 1034 as it conflicts with SOA/NS records. App Runner routes traffic for custom domains automatically once certificate validation records are in place. Also add preventDestroy lifecycle to the Route53 zone to guard against accidental deletion (which would require re-submitting NS records to the parent zone), and explicitly set enableWwwSubdomain: false on the custom domain association.
Code Review: Add Route53 custom domain for App Runner demo (latest iteration)This review is against the current commit ( Remaining Issues
|
Summary
10x-forms.labs.flexion.uspointing to the demo App Runner servicecustomDomainparameter toSandboxStackso DNS is only provisioned for stacks that need itlabs.flexion.usparent zoneResources created (demo stack only)
Route53Zonefor10x-forms.labs.flexion.usApprunnerCustomDomainAssociationlinking domain to App Runner serviceRoute53Recordentries for certificate validation CNAMEs (x3)Route53RecordCNAME pointing domain to App Runner service URLTerraformOutputwith NS records for parent zone delegationPost-apply
After
cdktf deploy, the output will include the 4 NS records that need to be configured as an NS record set for10x-formsin thelabs.flexion.ushosted zone (managed in another repo).