How instance termination works - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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.


				The IP addresses, RAM, instance store volumes, and EBS root volume are lost 
					when an instance is terminated.

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.

What happens when you terminate an instance

Changes registered at the OS level
  • The API request will send a button press event to the guest.

  • Various system services will be stopped as a result of the button press event. In Linux, systemd handles a graceful shutdown of the system. Graceful shutdown is triggered by the ACPI shutdown button press event from the hypervisor.

  • ACPI shutdown will be initiated.

  • The instance will shut down when 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 Amazon Fault Injection Service to test how your application responds when your instance is terminated. For more information, see the Amazon Fault Injection Service User Guide.