# Sensu automatically deregister EC2 instance

**URL:** https://discourse.sensu.io/t/sensu-automatically-deregister-ec2-instance/865
**Category:** Sensu Classic (EOL)
**Created:** [November 22, 2017, 4:36pm UTC](https://discourse.sensu.io/t/sensu-automatically-deregister-ec2-instance/865 "2017-11-22T16:36:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ferdous\_Shibly](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@Ferdous\_Shibly](https://discourse.sensu.io/u/Ferdous_Shibly)
#### Post date: [November 22, 2017, 4:36pm UTC](https://discourse.sensu.io/t/sensu-automatically-deregister-ec2-instance/865/1 "2017-11-22T16:36:22Z")

</div>

Hi,

I am trying to implement Sensu to check EC2 instances. We have some server in auto-scaling group. How can I configure sensu and cloudwatch events that will automatically deregister EC2 instances when autoscaling group scaled down? Could you share sample code or relative article with me?

Cheers

Ferdous Shibly

---

<div class="post-metadata">

### Author: ![Eric\_Heydrick](https://avatars.discourse-cdn.com/v4/letter/e/ce7236/32.png) [@Eric\_Heydrick](https://discourse.sensu.io/u/Eric_Heydrick)
#### Post date: [November 22, 2017, 5:58pm UTC](https://discourse.sensu.io/t/sensu-automatically-deregister-ec2-instance/865/2 "2017-11-22T17:58:15Z")

</div>

Check out [https://github.com/eheydrick/aws-cleaner](https://github.com/eheydrick/aws-cleaner). It listens for cloudwatch termination events and calls the Sensu API to remove instances when they are terminated.

> **···**
>
> On Wed, Nov 22, 2017 at 8:36 AM, Ferdous Shibly [bdshibly@gmail.com](mailto:bdshibly@gmail.com) wrote:
> 
> > Hi,
> 
> > I am trying to implement Sensu to check EC2 instances. We have some server in auto-scaling group. How can I configure sensu and cloudwatch events that will automatically deregister EC2 instances when autoscaling group scaled down? Could you share sample code or relative article with me?
> 
> > 
> 
> > Cheers
> 
> > Ferdous Shibly

---

<div class="post-metadata">

### Author: ![majormoses](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/majormoses/32/62_2.png) [@majormoses](https://discourse.sensu.io/u/majormoses)
#### Post date: [November 6, 2018, 4:48am UTC](https://discourse.sensu.io/t/sensu-automatically-deregister-ec2-instance/865/3 "2018-11-06T04:48:23Z")

</div>

I personally also use `aws-cleaner` and it works very well, one of the many benefits of this approach is that you can run multiple deprovisioning steps to update additional inventories such as config management tools. Some alternative approaches would be:

- [https://github.com/sensu-plugins/sensu-plugins-sensu/blob/master/bin/handler-sensu-deregister.rb](https://github.com/sensu-plugins/sensu-plugins-sensu/blob/master/bin/handler-sensu-deregister.rb)
- pay for enterprise which has this baked in
