Create DNS record

Create DNS record

prerequisite: Have a hosted zone, see create hosted zone on how to create such with CDK4J.

Map to IPv4 address

An A record is like a phonebook entry for the Internet: it tells the network which numeric address (IP) to use when someone types a website name.

A standard A record consists of four main parts:

  • zone: The domain area this record belongs to (think of a family name).
  • recordName: The part you add in front of the zone (like a person’s first name). recordName("ftp") + hosted zone cdk4j.com = ftp.cdk4j.com. The special @ equals the root domain (for example @ means in our example cdk4j.com).
  • target: The numeric IPv4 address where the server lives (like the server’s street address or phone number)
  • ttl (Time to Live): How long other DNS servers should remember this entry before checking again (measured in seconds). A longer TTL means fewer lookups but slower updates when you change the IP.
ARecord.Builder.create(this, "FtpA")
    .zone(hostedZone)
    .recordName("ftp")
    .target(RecordTarget.fromValues("185.233.172.70"))
    .ttl(Duration.hours(1))
    .build();

Assuming the hosted zone is cdk4j.com above ARecord will route users typing ftp.cdk4j.com to IP address 185.233.172.70.

Resources

  • [supported DNS records]({{ref “reference/aws-resources/route53/supported-dns-record-types”>}}) for the type of DNS records that can be defined.