Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (5.6k points)
I'm using AWS Auto Scaling in my environment and now I want to change the IP address manually in Route53. How to automate this process?

1 Answer

0 votes
by (12.4k points)
edited by

You can use the below code as a reference:

# !/bin/bash

INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)

PRIVATE_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)

DOMAIN_NAME=$(aws route53 get-hosted-zone --id "<Hosted Zone ID >" --query 'HostedZone.Name' --output text | sed 's/.$//')

hostnamectl set-hostname hostname."${DOMAIN_NAME}"

CN=`echo $PRIVATE_IP | cut -d . -f 3`

echo $CN

a=5

if [ $CN == $a ]

then

aws route53 change-resource-record-sets --hosted-zone-id "<Hosted Zone ID >" --change-batch '{"Changes": [{"Action": "UPSERT","ResourceRecordSet": {"Name": "'"Dns Name"'","Type": "A","TTL": 60,"ResourceRecords": [{"Value": "'"${PRIVATE_IP}"'"}]}}]}'

else

aws route53 change-resource-record-sets --hosted-zone-id "<Hosted Zone ID >" --change-batch '{"Changes": [{"Action": "UPSERT","ResourceRecordSet": {"Name": "'"< Dns Name>"'","Type": "A","TTL": 60,"ResourceRecords": [{"Value": "'"${PRIVATE_IP}"'"}]}}]}'

fi

Want to become AWS Expert? Come & join AWS Certification.

Related questions

+1 vote
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 1, 2020 in AWS by chandra (29.3k points)

Browse Categories

...