aws-samples / aws-lambda-ddns-function

Dynamically create Route 53 resource records using CloudWatch Events and Lambda
Apache License 2.0
236 stars 116 forks source link

Stopping/Terminating the instance, doesn't delete the A record of previous instance inside the private hosted zone #18

Closed mneeharika closed 7 years ago

mneeharika commented 7 years ago

Hi,

Creating an EC2 instance with the same ZONE, CNAME record, updates the previous CNAME record to map to new EC2 instance's internal DNS. However, the A record associated with the previous EC2 instance is not getting deleted/updated, instead a new A record to associate the internal to DNS to private IP.

jicowan commented 7 years ago

Thanks for the feedback. Can you describe a scenario where you would assign the same zone and CNAME record to an instance? As it's currently written, the records only get deleted when you terminate the instance.

mneeharika commented 7 years ago

Hi,

One scenario would be if we have to use this for auto-scaling groups. For example, if we have to have the DNS record to map to the IP of the latest instance in the ASG. When 1st instance is launched in ASG, one CNAME and one A record are created. When another instance is created in that ASG with same tags (suppose other app is using one internal dns to connect to this app's nodes), the CNAME record is updated, but A record is newly created leaving the old record. So, we with the current implementation, we will have to keep an eye to periodically clean up the old A records.

jicowan commented 7 years ago

This is an edge case that I didn't account for when I wrote the function. The A record isn't updated because the IP address of new instance is different than the first instance. Can you explain why you want to assign the same CNAME to multiple instances? You might want to consider putting the instances behind an ELB. Short of that, you could write a timed Lambda function to cull stale records from DNS.