1. Answers
  2. How To Handle Domain And Subdomain In One Route53 Record?

How to Handle Domain and Subdomain in One Route53 Record?

Handling Domain and Subdomain in One Route53 Record

In this guide, we will demonstrate how to handle both a domain and its subdomain within a single Route53 record using Pulumi. This involves creating an AWS Route53 hosted zone and adding record sets for both the domain and subdomain.

Step-by-Step Explanation

  1. Create a Route53 Hosted Zone: First, we need to create a hosted zone for our domain.
  2. Add Record Sets: Next, we will add record sets for both the domain and the subdomain within the hosted zone.

Summary

By following these steps, you can manage both your domain and subdomain within a single Route53 record using Pulumi. This approach simplifies DNS management and ensures consistency across your domain and subdomain configurations.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create a Route53 Hosted Zone
const hostedZone = new aws.route53.Zone("myHostedZone", {
    name: "example.com",
});

// Add a record set for the domain
const domainRecord = new aws.route53.Record("domainRecord", {
    zoneId: hostedZone.zoneId,
    name: "example.com",
    type: "A",
    ttl: 300,
    records: ["192.0.2.1"],
});

// Add a record set for the subdomain
const subdomainRecord = new aws.route53.Record("subdomainRecord", {
    zoneId: hostedZone.zoneId,
    name: "sub.example.com",
    type: "A",
    ttl: 300,
    records: ["192.0.2.2"],
});

export const hostedZoneId = hostedZone.zoneId;
export const domainRecordName = domainRecord.name;
export const subdomainRecordName = subdomainRecord.name;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up