Delete Instances
Delete EC2 instances and, optionally, any associated resource types.
Steps:
- Discover associated resources for each instance (images, volumes, snapshots)
- If specified, disable termination and stop API protections
- If any of the instances are running, stop them
- If specified, create an image (AMI) before proceeding with deletion
- Delete the instances
- If specified, delete associated resources
This action does not automatically disable termination or stop protection before deletion.
To achieve this, supply the disable_protections parameter.
Usage
Input
Parameter | Description | Type | Required | Default Value |
---|---|---|---|---|
instance_ids | Instance IDs to delete | list(string) | Yes | None |
include | Associated resource types to delete volume , image , snapshot | list(string) | No | None |
final_image | Create an image (AMI) before deletion | bool | No | False |
disable_protections | Disable termination and stop protection before deletion | bool | No | False |
region | Region for operation. Leave blank for session default | string | No | Session Default |
debug | Increase log verbosity | bool | No | False |
silent | Decrease log verbosity | bool | No | False |
output | Output format table | string | No | None |
session | Established session | object | No | None |
Output
Returns a dictionary
of resources that failed the deletion:
{
"Instances": ['i-1234567890abcdef0'],
"Volumes": ['vol-1234567890abcdef0'],
"Images": ['ami-1234567890abcdef0'],
"Snapshots": ['snap-1234567890abcdef0']
}
Examples
Delete instances with pre-deletion images (AMIs):
aaws ec2 delete_instances --instance_ids i-1234567890abcdef0 i-abcdef1234567890 --final_image
Delete instances and associated resources:
aaws ec2 delete_instances --instance_ids i-1234567890abcdef0 i-abcdef1234567890 --include volume image snapshot