AWS: Terminate an EC2 Instance Belonging to an ASG
Availability
This workflow action is available only to customers on PagerDuty Operations Cloud plans. See Operations Cloud pricing for more information.
Description
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
- If you have not done so, follow the instructions to Create an Incident Workflow.
- When the instructions prompt you to add actions, select this action.
- Enter the following Inputs and click Save.
- Continue following instructions to Publish the Workflow.
- When the action runs, you will see the Outputs listed below.
Inputs
Field References
Fields with the {+} icon accept 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 article for more information.
| Name | Description |
|---|---|
| Integration | Select a Workflow Integration 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.
Updated about 2 hours ago
