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?

  • 1
    Send it somewhere during the shutdown process? – a CVn Jun 9 '16 at 13:44
  • Are you sure you can access instance using private IP after its terminated ? I did not understand the question properly. Why do you want to clean up after terminating, isn't everything cleaned up automatically by AWS after an instance is terminated ? – Rahul Prasad Jun 9 '16 at 14:23
  • There is no shutdown process unfortunately... – Jim March Jun 9 '16 at 15:05
  • @RahulPrasad I'm not accessing the instance itself, it's gone. But in Active Directory, and many other applications, remnant computer accounts exist that need to be removed... – Jim March Jun 9 '16 at 15:06
  • exists where ? in the instance that is lost or in some other instance ? please be clear about the question, specify as much details as possible, give an example if possible. – Rahul Prasad Jun 9 '16 at 15:19

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.

  • This looks promising. I'll run some tests to see if it's possible. I was using CloudWatch events to write to an SQS queue, which is processed every 5 minutes. I may need to have the autoscaling:EC2_INSTANCE_TERMINATING feed a lambda function, or something else to get the Private IP before it's actually terminated. – Jim March Jun 9 '16 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.