Update Route53 with home public IP or from EC2 Metadata

In this post, you will find how to update AWS Route53 from your current public IP (ISP) and how to use EC2 instance metadata to change your DNS A Record.

Requirements

To use this script, you will need:

  • awscli (pip install awscli)
  • dig (apt-get install dnsutils)

Update Route53 with your current home Public IP

First, I was facing an issue with my current ISP with non-static IP address, so I found a useful script to update AWS Route53 on a daily basis from my RaspberryPi.

Please find the how-to on my GitHub

Update Route53 with your current EC2 Metadata from an instance in an ASG

I didn’t want to setup an ALB/ELB because it cost too much for my needs (labs). So I’ve adapted this article to meet my needs.

Follow the same steps and adapt Update53-EC2Pub.sh and UserData from my Launch Configuration below:

update-route53-A.json & Update53-EC2Pub.sh:

UserData:

In this example, I’ve compressed and hosted source in a simple S3 bucket, and using it with UserData instance.

#!/bin/bash

/usr/bin/aws s3 cp  s3://YOU_S3_BUCKET/update53.tar.bz2  /home/ec2-user/
tar xjvf /home/ec2-user/update53.tar.bz2 -C /home/ec2-user/
rm /home/ec2-user/update53.tar.bz2
/bin/sh /home/ec2-user/update53/update.sh >> /home/ec2-user/update53.log
rm -rf /home/ec2-user/update53/

It’s working pretty well, with scheduled actions on my ASG, my instance is shutting down at night every day, and fire-up on the next morning, the public IP is automatically updated to my AWS Route53 A Record.

Don’t hesitate to ping me with any question

zoph

Leave a Comment