Amazon Route 53 records

Warning: Long post ahead!
TL;DR = Download the script here:

Now that I’ve got website hosting set up, it would be nice to point the domain to it 🙂

In order to do so, I’ll need an A record for to point to

But there’s no quick way to do it via PowerShell. And while R53 is easy to configure using AWS Console, that’s not what we want.

Let’s see which commandlets we have for Route 53 interaction.

There we go, third one – Edit-R53ResourceRecordSet. In total we have 72 commandlets, but I’ll save you the trouble from going through all of them.
Make sure to check the commandlet reference on AWS website.

We need a HostedZoneId and an object for ChangeBatch_Change.

Let’s get the hosted zone first.

Less commandlets this time 🙂 We will need Get-R53HostedZones .

Great! We have our hosted zone ID and name.
Now, for the next part of Edit-R53ResourceRecordSet – the change object parameter.

To see clearly what to do, let’s consult my all-time favorite PowerShell command – Get-Help!

First example has everything we need! Well, except for one thing – Action: UPSERT. But if you read the commandlet reference from AWS site linked above (as I nicely asked you to 🙂 ), you’ll know what it is.
I know you’re lazy, so here’s a definition: “If a resource record set does not already exist, AWS creates it. If a resource set does exist, Amazon Route 53 updates it with the values in the request.” Neat, huh?

I’m going to use UPSERT instead of CREATE for obvious reasons. We can even implement DELETE if there’s time.

Here we go. Let’s create an object and set UPSERT action.

Now we create ResourceRecordSet object and use our variables for various options.

And we finish with forming our parameter hash table.

But… there’s something missing 🙂 Plenty missing, actually, but let’s start with the obvious thing – $Hostedzone.Id. We never defined it, so we need to do so above the last snippet.

Now, what in the world is $DomainDot?? Well, we could go with $Domain that we’ll require from the user. But how to be sure user used instead of

We can’t. Therefore we’ll make sure there’s a dot at the end.

One last touch – parameters. Our script will have a few mandatory ones, and we need to clearly define them. One we can consider default unless changed (TTL of 5 minutes) and one we can ignore unless specified (Comment). That leaves 4 variables we must request from the user in order to run the script – Domain name as well as type, name and the value of DNS record.

Et voila!
Our job is done!

Let’s take a look at the final script.

Download the script from Amazon S3:

There are still a few things left to be done in order to really really have a finished script. For example, introduce DELETE action to complement our CREATE/UPSERT one and test input parameters. We won’t have our users feeding random stuff to the script, right? 🙂
Also don’t forget to Import-Module AWSPowerShell. That’s kind of a big deal 😉

Last thing – You’ll find there’s an extra commented line. When you try to enter an SPF record (think quotes), you’ll figure out why the change 🙂

This is it.
To use the function, save it to a file and name Set-R53Record.ps1 or however you like. Dot source it and run, include in your awesome DNS update script, do as you wish.

I know I have 0 active readers at the moment, and it would be a miracle otherwise since I just created an A record for the website, but I would be very interested in hearing how you implemented Amazon Route 53 DNS management using PowerShell.

Did you use my function? Did you find another one? Have I, Gods forbid, helped you build your own? 🙂

Let me know at
Just… give me a few days to set up a mail server (and MX record!) 🙂 🙂 🙂

I almost forgot!
Here’s how I ended up using this script to create a WWW A DNS record for


  1. Carl Reply

    Thanks, this was very helpful and saved me a ton of time. I have updated the code to work with weighted routing and alias types but the work you did really got me going because let’s be honest, AWS have not exactly made this obvious have they?

  2. Steven Reply

    This worked out great. Exactly what I needed and much cleaner than what I was cobbling together. Thanks !

    • Six Reply

      I write this blog basically for myself, as an exercise. But I’m very happy to see that this is actually helping people! 🙂

  3. Six Reply

    I also suck at following my own posts and replying on time 🙂

  4. Alexandre Reply

    If you want to use it without function, you must add this line :

    add-type -path “C:\Program Files (x86)\AWS SDK for .NET\past-releases\Version-2\Net45\AWSSDK.dll”

    • Six Reply

      Ufff… this was written a long time ago! Both my post and your comment 🙂
      There are better ways to do this now. Also, starting with PowerShell 3.0 modules are being imported automatically if they contain a cmdlet you’re calling.

Leave a Comment