How instance termination works
When you terminate an instance, changes are registered at the OS level of the instance, some resources are lost, and some resources persist.
The following diagram shows what is lost and what persists when an Amazon EC2 instance is terminated. When an instance terminates, the data on any instance store volumes and the data stored the instance RAM is erased. Any Elastic IP addresses associated with the instance are detached. For Amazon EBS volumes and the data on those volumes, the outcome depends on the Delete on termination setting for the volume. By default, the root volume is deleted and the data volumes are preserved.
Considerations
-
When an instance terminates, the data on any instance store volumes associated with that instance is deleted.
-
By default, Amazon EBS root device volumes are automatically deleted when the instance terminates. However, any additional EBS volumes that you attach at launch, or any EBS volumes that you attach to an existing instance persist even after the instance terminates. For more information, see Preserve data when an instance is terminated.
Note
Any volumes that are not deleted upon termination of the instance will continue to incur charges.
-
To prevent an instance from being accidentally terminated by someone, enable termination protection.
-
To control whether an instance stops or terminates when shutdown is initiated from the instance, change the instance initiated shutdown behavior.
-
If you run a script on instance termination, your instance might have an abnormal termination, because we have no way to ensure that shutdown scripts run. Amazon EC2 attempts to shut an instance down cleanly and run any system shutdown scripts; however, certain events (such as hardware failure) may prevent these system shutdown scripts from running.
-
x86 bare metal instances do not support cooperative shutdown.
What happens when you terminate an instance
Changes registered at the OS level
-
The API request sends a button press event to the guest.
-
Various system services are stopped as a result of the button press event. Graceful shutdown of the system is provided by systemd (Linux) or the System process (Windows). Graceful shutdown is triggered by the ACPI shutdown button press event from the hypervisor.
-
ACPI shutdown is initiated.
-
The instance will shut down after the graceful shutdown process exits. There is no configurable OS shutdown time. The instance remains visible in the console for a short time, then the entry is automatically deleted.
Resources lost
-
Data stored on an instance store volume.
-
Data stored on Amazon EBS root device volumes if the
DeleteOnTermination
attribute is set to true.
Resources that persist
-
Data stored on additional Amazon EBS volumes attached at launch or after launch of an instance.
Test application response to instance termination
You can use AWS Fault Injection Service to test how your application responds when your instance is terminated. For more information, see the AWS Fault Injection Service User Guide.