Skip to content

Instantly share code, notes, and snippets.

@ffjia
Forked from tcbyrd/README.md
Created January 19, 2021 03:17
Show Gist options
  • Save ffjia/67ef6e6084646759b3a3676d2216341f to your computer and use it in GitHub Desktop.
Save ffjia/67ef6e6084646759b3a3676d2216341f to your computer and use it in GitHub Desktop.
Route53 CNAME Update

AWS CLI command to update CNAME

When you have a set of application servers running in EC2 in an active/passive configuration, the easiest way to failover is to simply update the DNS to point to the second server as soon as it's available to serve requests. If you are using Route 53 to manage your DNS configuration, with the AWS CLI you can make this change in a single command.

Initial Setup

The CLI expects the change to be submitted via a JSON-formatted configuration file. I've included a short example in this gist that just updates the cname. For a full list of options available, check out the AWS Command Line reference

Command

Assuming the the CLI is properly configured and a change file called change-cname.json file in your current working directory:

aws route53 change-resource-record-sets --hosted-zone-id [[HostedZoneID]] --change-batch file://change-cname.json
{
"Comment":"Updates CNAME to a specified value",
"Changes":[{
"Action":"UPSERT",
"ResourceRecordSet":{
"Name":[[PUBLIC DNS NAME]],
"Type":"CNAME",
"TTL":30,
"ResourceRecords":[{
"Value":[[TARGET HOST NAME]]
}]
}
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment