Getting the private ip address of a recently terminated ec2 instance in aws

amazon-web-services

When terminating EC2 instances, I need to be able to clean up remnants from the servers. Like removing the computer object from Active Directory, Chef, Octopus Deploy, Cyclance, etc…

None of these server applications are aware of the Instance ID in AWS, but they can all be found by the IP address.

When the EC2 instance is terminated, the private IP address is immediately removed and unable to be queried.

Is there anyway to find out what the Private IP address of terminated instance was?

Best Answer

It is possible when you deployed the instance via auto-scaling. It is tricky but possible: Auto Scaling Lifecycle Hooks

So, when instance going to be terminated, 'autoscaling:EC2_INSTANCE_TERMINATING' triggered.

enter image description here

p.s. Didn't try it myself yet, so there are not much details.

p.p.s. Perhaps using similar hooks it is possible to work with instanced not in Auto Scaling, but unsure.