How EC2 instance stop and start works - Amazon Elastic Compute Cloud

How EC2 instance stop and start works

When you stop an instance, changes are registered at the OS level of the instance, some resources are lost, and some resources persist. When you start an instance, changes are registered at the instance level.

The following diagram shows what is lost and what persists when an Amazon EC2 instance is stopped. When an instance stops, it loses any attached instance store volumes and the data stored on those volumes, the data stored on the instance RAM, and the assigned public IPv4 address if an Elastic IP address is not associated with the instance. An instance retains assigned private IPv4 addresses, Elastic IP addresses associated with the instance, any IPv6 addresses, and any attached Amazon EBS volumes and the data on those volumes.

The public IPv4 address, RAM, and instance storage data are lost when an instance is stopped.

What happens when you stop 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 is triggered by the ACPI shutdown button press event from the hypervisor.

  • ACPI shutdown is initiated.

  • The instance shuts down when the graceful shutdown process exits. There is no configurable OS shutdown time.

  • If the instance OS does not cleanly shut down within a few minutes, a hard shutdown is performed.

  • The instance stops running.

  • The instance status changes to stopping and then stopped.

  • [Auto Scaling] If your instance is in an Auto Scaling group, when the instance is in any Amazon EC2 state other than running, or if its status for the status checks becomes impaired, Amazon EC2 Auto Scaling considers the instance to be unhealthy and replaces it. For more information, see Health checks for Auto Scaling instances in the Amazon EC2 Auto Scaling User Guide.

  • [Windows instances] When you stop and start a Windows instance, the launch agent performs tasks on the instance, such as changing the drive letters for any attached Amazon EBS volumes. For more information about these defaults and how you can change them, see Use the EC2Launch v2 agent to perform tasks during EC2 Windows instance launch.

Resources lost
  • Data stored on the RAM.

  • Data stored on the instance store volumes.

  • The public IPv4 address that Amazon EC2 automatically assigned to the instance upon launch or start. To retain a public IPv4 address that never changes, you can associate an Elastic IP address with your instance.

Resources that persist
  • Any attached Amazon EBS volumes.

  • Data stored on the attached Amazon EBS volumes.

  • Private IPv4 addresses.

  • IPv6 addresses.

  • Elastic IP addresses associated with the instance. Note that when the instance is stopped, you are charged for the associated Elastic IP addresses.

For information about what happens when you stop a Mac instance, see Stop or terminate your Amazon EC2 Mac instance.

What happens when you start an instance

Changes registered at the OS level
  • In most cases, the instance is migrated to a new underlying host computer (though in some cases, such as when an instance is allocated to a host in a Dedicated Host configuration, it remains on the current host).

  • Amazon EC2 assigns a new public IPv4 address to the instance if the instance is configured to receive a public IPv4 address. To retain a public IPv4 address that never changes, you can associate an Elastic IP address with your instance.

Test application response to stop and start

You can use AWS Fault Injection Service to test how your application responds when your instance is stopped and started. For more information, see the AWS Fault Injection Service User Guide.

Costs related to instance stop and start

The following costs are associated with stopping and starting an instance.

Stopping — As soon as the state of an instance changes to shutting-down or terminated, charges are no longer incurred for the instance. You are not charged for usage or data transfer fees for a stopped instance. Charges are incurred to store Amazon EBS storage volumes.

Starting — Each time you start a stopped instance, you are charged for a minimum of one minute of usage. After one minute, you are charged for only the seconds you use. For example, if you run an instance for 20 seconds and then stop it, you are charged for a minute of usage. If you run an instance for 3 minutes and 40 seconds, you are charged for 3 minutes and 40 seconds of usage.