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

Shorn
preguntada hace un año40 visualizaciones
No hay respuestas

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas