CDK: How to set the TTL of the NS record for a Route53 PublicHostedZone?

1

Problem

I created a Route 53 zone with the following code:

this.apiV2Zone = new PublicHostedZone(this, "ApiV2", {
  zoneName: "api-v2.example.com"
});

The zone was created as expected, but I noticed the TTL attribute for the NS record was set to 172800 (2 days). This is a bit high at the moment, because I'm just experimenting - setting the TTL lower won't cost me much for now.

But, how do I go about seting the TTL of the NS record with the CDK?


What I've tried

I tried to force the NS record myself with:

let target = RecordTarget.fromValues(
  ...this.apiV2Zone.hostedZoneNameServers ?? [] );
const recordSet = new RecordSet(this, 'ApiV2Ns', {
  recordType: RecordType.NS,
  target,
  zone: this.apiV2Zone,
  deleteExisting: true,
  recordName: this.apiV2Zone.zoneName,
  ttl: cdk.Duration.minutes(10),
});

But that failed on deploy with:

 Received response status [FAILED] from custom resource. Message returned: InvalidChangeBatch
: [A HostedZone must contain at least one NS record for the zone itself.]

Also tried with deleteExisting: false but that failed too because it was duplicating the existing NS record.


Workaround

Set it manually in the AWS console. Doesn't seem to cause any change to be reported when I do a CDK diff.


https://stackoverflow.com/questions/75217593/cdk-how-to-set-the-ttl-of-the-ns-record-for-a-route53-publichostedzone

Sem respostas

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas