# AWS: Terminate an EC2 Instance Belonging to an ASG

Terminates a specific EC2 instance in an Auto Scaling Group, with an option to decrement the group's desired capacity afterward.


> **Availability:** See the [Incident Workflow Actions Overview table](/workflow-actions) for the plans this workflow is available on.

## Description

**Premium.** This action is a Premium Workflow Action, billed separately from your PagerDuty plan. In the workflow action picker, this action appears as **EC2: Terminate Instances**.

Terminate an EC2 instance that belongs to an Auto Scaling Group (ASG). You can choose whether to decrement the ASG's desired capacity when the instance is terminated. This action is useful for:

- Completing an instance-rotation runbook after the instance has been moved to Standby and a replacement is in service
- Removing an unhealthy or problematic instance from the group and optionally letting the ASG launch a replacement (when **Should Decrement Desired Capacity** is **false**)
- Automating termination as part of a multi-step workflow that includes Describe Auto Scaling Instances, Set Instance Protection, Enter Standby, and a delay
- Recording the termination activity (activity ID, cause, description, status) for audit or incident notes

## Instructions

1. If you have not done so, follow the instructions to [Create an Incident Workflow](/ai-automation/automation/incident-workflows#create-an-incident-workflow).
2. When the instructions prompt you to [add actions](/ai-automation/automation/incident-workflows#add-actions), select **this action**.
3. Enter the following **Inputs** and click **Save**.
4. Continue following instructions to **Publish** the Workflow.
5. When the action runs, you will see the **Outputs** listed below.

## Inputs

> **Field References:** Fields with the **\{+\}** icon accept [Field References](/ai-automation/automation/incident-workflows#field-references), which can be useful for referencing incident data or outputs created in prior workflow steps. To add Field References, click **\{+\}**, or enter `{{`, and select relevant fields. Refer to the [Field References](/ai-automation/automation/incident-workflows#field-references) article for more information.

| Name                              | Description                                                                                                                                                                                                                                |
| :-------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Integration                       | Select a [Workflow Integration](/ai-automation/automation/incident-workflows/workflow-integrations) or click **New AWS Connection** to establish a new one.                                                                                     |
| Instance ID                       | The EC2 instance ID to terminate. Must be an instance that belongs to an Auto Scaling Group.                                                                                                                                               |
| AWS Region                        | The AWS region where the instance and ASG are located. If left blank, the action uses `us-east-1` as the default.                                                                                                                          |
| Should Decrement Desired Capacity | Whether to reduce the ASG's desired capacity when this instance is terminated. Default: **false**. Set to **false** when a replacement is already in service (e.g., after Enter Standby and a delay); set to **true** to shrink the group. |

## Outputs

| Name           | Description                                                                                                                                                                                                  |
| :------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Activity       | JSON object for the Auto Scaling activity: **activityId**, **cause**, **description**, **statusCode**, **startTime**, **endTime** (null until the activity completes). Use this for incident notes or audit. |
| Result         | Whether the action succeeded: **Success** or **Failed**.                                                                                                                                                     |
| Result Summary | Brief description of what the action did or if it failed.                                                                                                                                                    |
| Error          | Error message, if the action failed.                                                                                                                                                                         |

> **Tips:** - **Instance Rotation**: In a rotate-instance runbook, run **Enter Standby** and a **Delay** step first so a replacement instance is in service before terminating. Use **Should Decrement Desired Capacity** = **false** so the group size stays the same.
> - **Field References**: Reference the **Instance ID** from **Auto Scaling: Describe Auto Scaling Instances** (e.g., `instances[0].instanceId`) or from the incident's custom details so the workflow works when triggered by an alert.
