AWS - Create a CNAME Record for a Database

2021-09-08

// other cdk code
const db = new rds.DatabaseInstance() // create a database instance
const zone = route53.HostedZone.fromLookup(this, 'HostedZone', { domainName })

cname = new route53.CnameRecord(this, 'cname', {
  zone,
  recordName: 'database',
  domainName: db.dbInstanceEndpointAddress,
  ttl: cdk.Duration.seconds(300)
})
// other cdk code

Context

I wanted to attach a domain name to a database I created with the rds CDK constructs. I had only created alias records to this point with the CDK so I assumed the process was similar. However, AWS can only create alias records for a limited set of AWS resource. RDS isn't one of them. Instead, create a CNAME record and point it to the DNS name of the database.

This domainName prop expects a DNS name from an AWS service. Most CDK constructs return a class with method to return this DNS name. In this case that is db.dbInstanceEndpointAddress.

About

Home

Contact Me

mitchell@gritts.me

This Site

Built by me. Writing and images are my original work unless otherwise noted. Please attribute this site when sharing.

This content served from this URL (mitchell.gritts.net) is licensed with the Unlicense. Content served from other URLs may have other licenses. The repo is currently private while I actively build out the site.