Logo Dark
Get in Touch

How to Create Dynamic DNS in AWS Route 53 Using Python and the AWS SDK

22 October 2024

Web
Tech

Table of contents

What Is Dynamic DNS?

Why we need Dynamic DNSšŸ¤”?

Dynamic DNS Service Providers (FreešŸ¤“):

  1. https://www.noip.com/
  2. https://www.dynu.com/

Do Route 53 have this amazing feature šŸ™„?

So, How do we do it šŸ˜¼?

  1. Create Route 53 Hosted Zone of your domain and note the Hosted Zone ID.
Creating Route 53 Hosted Zone

Creating Records

Creating One Iam User

sudo apt update

mkdir ddns && cd ddns

nano ddns.py

sudo apt install python3-boto3
sudo apt install python3-requests

sudo chmod +x ddns.py

python3 ddns.py

IP Address up to Date

How to run this code on instance boot upšŸ?

  1. Create systemd service file:
sudo nano /etc/systemd/system/update-dns.service

[Unit]
Description=Update Route 53 DNS with Public IP
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/ubuntu/ddns/ddns.py
WorkingDirectory=/home/ubuntu/
StandardOutput=inherit
StandardError=inherit
Restart=always
User=ubuntu

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload
sudo systemctl enable update-dns.service
sudo systemctl start update-dns.service

How to run this script every 5 min?

  1. Edit crontab file:
crontab -e

*/5 * * * * /usr/bin/python3 /home/ubuntu/ddns/update_dns.py

sudo systemctl enable cron
sudo systemctl start cron

sudo systemctl status cron

How Useful it is?

References:

  1. https://aws.amazon.com/what-is/dynamic-dns/
  2. https://github.com/nishant-p-7span/Dynamic-DNS/tree/Custom-DDNS
  3. ChatGPT šŸ˜‰.

WRITTEN BY

Pruthvi Menpara

Pruthvi is a cloud computing architect who makes sure businesses scale and perform at their best using AWS and Azure. Heā€™s passionate about building robust cloud infrastructures that provide the perfect balance of security and scalability.

More from this author

Making IT Possible

Making IT Possible

Making IT Possible

Making IT Possible

Making IT Possible

Making IT Possible

India (HQ)

201, iSquare Corporate Park, Science City Road, Ahmedabad-380060, Gujarat, India

Canada

24 Merlot Court, Timberlea, NS B3T 0C2, Canada

For Sales

[email protected]

Looking For Jobs

Apply Now

LinkedIn
Instagram
X
Facebook
Youtube
Discord
Dribbble
Behance
Github