We have an autoscaling group with n no. of ec2 instances. We have a route53 record set (multi wieght) created which points to the ip address of autoscaling group. For every ec2 scaling action, i wanted to query the running instances in autoscaling group and update the dns using the userdata script.
I am using aws cli to query the ec2 instances running in the autoscaling group:
aws autoscaling describe-auto-scaling-instances --region us-east-1 --output text --query "AutoScalingInstances[?AutoScalingGroupName=='myapp-asg'].InstanceId" | xargs -n1 aws ec2 describe-instances --instance-ids $ID --region us-east-1 --query "Reservations[].Instances[].PrivateIpAddress" --output text
This gives all the ipaddress in the autoscaling group in below format:
20.91.0.1
20.91.0.2
20.91.0.3
20.91.0.4
Using aws cli i want to update the dns. Below is the command i am using:
aws --region us-east-1 route53 change-resource-record-sets --hosted-zone-id "Zone-id" --change-batch '{"Changes": [{"Action": "UPSERT","ResourceRecordSet": {"Name": "'"myrecord.mydomain.com"'","Type": "A","TTL": 60,"Weight": 200,"SetIdentifier":"myrecord","ResourceRecords": [{"Value": "20.91.0.1"},{"Value": "20.91.0.2"}]}}]}'
How do I automate the ipadress which i get from the first command to update the values for record sets in the second command