---
title: "Retrace Auto Scaling in AWS"
slug: "auto-scaling-with-aws"
description: "Automatically remove inactive AWS autoscale group instances from Retrace's Servers page using AWS Lambda. Follow the steps to set up a trigger for seamless removal."
updated: 2018-10-30T16:01:26Z
published: 2018-10-30T16:01:26Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Auto Scaling Events

If you have [AWS autoscale groups](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html) (including EBS instances), you may notice that inactive instances aren't being removed from the Retrace's Servers page dynamically during a scale down event. The following steps will guide you through the process of creating a trigger that will automatically remove the instances (servers) from Retrace so that inactive servers don't stick around in the Retrace.

## Create a new AWS Lambda Function

To create a new [Lambda Function](https://aws.amazon.com/lambda/), you will want to select "Author from scratch". Here you will name the function, select the runtime (use Node.js 6.10 or later), and select a role to run the function.

> **Note:** Lambda Functions are region-specific, so be sure to create the function(s) in the same region(s) where you deploy your application.

![2018-07-19 13_52_29.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/6409f6a2-0611-47d7-b1b8-5aca5bccf4bb.png)

## Upload the Function Code to your Lambda Function

After you create your function, you will want to add the code that will programmatically remove the servers when a scale down event occurs.

Download the index.zip file from our [Github page](https://github.com/stackify/stackify-aws-lambda) and then upload the zip into your function.

[Download the .zip file](https://github.com/stackify/stackify-aws-lambda/raw/master/index.zip)

Then under Code Entry Type select "Upload a .Zip file" ![2018-07-19 15_25_14-Lambda Management Console.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/4acfd518-01bd-4fe5-90aa-cc687b7e07eb.png)

## Add the Stackify API Key as an Environment Variable

![2018-07-19 15_27_04-Lambda Management Console.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/d29cf8af-4921-4efe-afe6-2c78c810c8a9.png)

| Key | Value |
| --- | --- |
| Stackify_ApiKey | YOUR_API_KEY |

## Configure a CloudWatch Events Trigger

The next step is to create the trigger that will define when the function runs. To create the trigger, select CloudWatch Events and navigate to the "Configure triggers" section.

![2018-07-19 15_42_05-Lambda Management Console.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/cc9c184f-2541-484a-8fc1-b7fc9b31a62e.png)

Here you will create and name a new rule, assign the Rule type as "Event pattern", select the "Instance launch and terminate" event, and use the "EC2 Instance Terminate Successful" event type.

![2018-07-20 09_54_28-Lambda Management Console.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/4c8e1fe0-946c-4a5d-9c50-3cc86889b98d.png)

Once configuration is complete, add the event and save your Lambda function.

Now every time an instance is terminated, the server instance will automatically removed from the Retrace Servers page.
