Problem
In my dev environment I want to create easy to remember ordinal dns names for ECS cluster hosts. When we deploy we scale out from 1 to 2 hosts and then drain/scale back in.
At present we use userdata like so so set the dns name
INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
INSTANCE_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
RECORD_CONFIG="/tmp/ecs-a-record.json"
cat >>$RECORD_CONFIG << ROUTE53
{
"Comment": "Create a friendly DNS name for the DOD ECS host",
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "dev-ecs.ourenv.dev",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{ "Value": "$INSTANCE_IP"}]
}
}]
}
ROUTE53
aws route53 change-resource-record-sets --hosted-zone-id ... --change-batch file://$RECORD_CONFIG
I think my options are
- probe dns name and if its in use, increment a counter, try again with N+1
- use aws cli to gather data about the ASG instances and use launch time to determine ordinal name
Does anyone know of a more elegant solution?
So, here's how we manage convenience fqdns records for devTest environments. This becomes important when we scale the cluster to ensure the 2nd/3rd hosts don't attempt to take the 1st host's name