How Do I Use AWS Route53 With RDS?
Introduction
In this guide, we will walk you through the process of integrating Amazon RDS with AWS Route53 to manage DNS records. Specifically, we will set up a MySQL RDS instance and create a Route53 DNS record to point to the RDS instance’s endpoint. This setup ensures that your database can be easily accessed using a domain name.
Steps
1. Create an RDS Instance
- We will create an Amazon RDS instance running MySQL. This involves specifying the instance class, storage, and database credentials.
2. Create a Route53 Hosted Zone
- Set up a hosted zone in Route53 to manage the DNS records for your domain. This hosted zone will serve as the DNS authority for the domain.
3. Create a Route53 DNS Record
- Create a DNS record in Route53 that points to the RDS instance endpoint. This record will be of type
CNAME
and will map a domain name to the RDS instance.
Prerequisites
- Ensure you have the Pulumi CLI installed and configured.
- Configure AWS credentials for Pulumi.
- Have a domain name registered with Route53.
Pulumi Program
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Configuration
const dbConfig = {
instanceClass: "db.t2.micro",
allocatedStorage: 20,
engine: "mysql",
engineVersion: "8.0",
name: "mydatabase",
username: "admin",
password: "password1234",
skipFinalSnapshot: true,
};
// Create a new RDS instance
const rdsInstance = new aws.rds.Instance("my-rds-instance", {
instanceClass: dbConfig.instanceClass,
allocatedStorage: dbConfig.allocatedStorage,
engine: dbConfig.engine,
engineVersion: dbConfig.engineVersion,
name: dbConfig.name,
username: dbConfig.username,
password: dbConfig.password,
skipFinalSnapshot: dbConfig.skipFinalSnapshot,
});
// Create a Route53 hosted zone
const hostedZone = new aws.route53.Zone("myHostedZone", {
name: "mydomain.com",
});
// Create a Route53 DNS record pointing to the RDS instance
const dbRecord = new aws.route53.Record("dbRecord", {
zoneId: hostedZone.id,
name: "database.mydomain.com",
type: "CNAME",
ttl: 300,
records: [rdsInstance.endpoint],
});
// Export the DNS name of the RDS instance
export const dbEndpoint = rdsInstance.endpoint;
export const dbDnsName = dbRecord.fqdn;
Explanation
RDS Instance
- An RDS instance is created using the
aws.rds.Instance
resource. - It is configured with the MySQL engine, specifying the instance class, storage, and database credentials.
Route53 Hosted Zone
- A hosted zone is created using the
aws.route53.Zone
resource. - This zone manages DNS records for
mydomain.com
.
Route53 DNS Record
- A DNS record is created using the
aws.route53.Record
resource. - The record points to the RDS instance endpoint and is of type
CNAME
.
Exports
- The RDS instance endpoint and the fully qualified domain name (FQDN) of the DNS record are exported for external use.
Conclusion
This guide has demonstrated how to set up an RDS instance and configure AWS Route53 to manage its DNS records. By following these steps, you can ensure that your database is accessible via a domain name, simplifying connectivity and management. You can use Pulumi to execute this program and provision the necessary infrastructure in your AWS account.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.