Stop and start your instance - 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).

Stop and start your instance

You can stop and start your instance if it has an Amazon EBS volume as its root device. The instance retains its instance ID, but can be modified as described in the Modify a stopped instance section. When you stop an instance, the instance shuts down. When you start an instance, the instance is typically migrated to a new underlying host computer and assigned a new public IPv4 address.

When you stop an instance, it is not deleted. If you decide that you no longer need an instance, you can terminate it. For more information, see Terminate your instance. If you want to hibernate an instance to save the contents from the instance memory (RAM), see Hibernate your On-Demand Instance or Spot Instance. For distinctions between instance lifecycle actions, see Differences between reboot, stop, hibernate, and terminate.

Amazon can schedule events for your instances, such as reboot, stop/start, or retirement. For information about the type of scheduled events that are managed by Amazon, and how to view and receive notifications about scheduled events, see Scheduled events for your instances.

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.

Costs related to starting and stopping an instance

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.

Find all running and stopped instances

You can find all of your running and stopped instances across all Amazon Web Services Regions on a single page using Amazon EC2 Global View. This capability is especially useful for taking inventory and finding forgotten instances. For information about how to use Global View, see Amazon EC2 Global View.

Prerequisites for stopping an instance

You can stop an Amazon EBS-backed instance. Instances backed by an instance store volume do not support the Stop action. To better understand the differences between the two volume types, see Storage options for your Amazon EC2 instances.

To verify the root device type of an instance, you can use the Amazon EC2 console or the Amazon CLI.

Amazon EC2 console

In the Amazon EC2 console, open the Instances pane and select an instance. The Root device type is listed on the Storage tab, under Root device details.

Amazon CLI

You can verify the root device type of an instance by running the describe-instances Amazon CLI command and checking the output for RootDeviceType: ebs or instance-store. For more information, see describe-instances in the Amazon CLI Command Reference.

Manually stop and start an instances

You can stop and start your Amazon EBS-backed instance using the console or the command line.

Warning

When you stop an instance, the data on any attached instance store volumes is erased. Before you stop an instance, verify that you've copied any data that you need from your instance store volumes to persistent storage, such as Amazon EBS or Amazon S3. Instances backed by an instance store volume do not support the Stop action.

Console
To stop and start an Amazon EBS-backed instance
  1. Sign in to the Amazon Web Services Management Console and open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. In the left navigation pane, choose Instances and select the instance.

  3. Choose Instance state, Stop instance. If this option is disabled, either the instance is already stopped or its root device is an instance store volume.

  4. When prompted for confirmation, choose Stop. It can take a few minutes for the instance to stop.

  5. (Optional) While your instance is stopped, you can modify certain instance attributes. For more information, see Modify a stopped instance.

  6. To start a stopped instance, select the instance, and choose Instance state, Start instance.

  7. It can take a few minutes for the instance to enter the running state.

Command line
To stop and start an Amazon EBS-backed instance

Run one of the following commands:

Using the OS halt command from an instance does not initiate a shutdown. If you use the halt command, the instance does not terminate; instead, it places the CPU into HLT, which suspends CPU operation. The instance remains running.

Automatically stop and start your instances

You can automate stopping and starting instances with the following services:

Instance Scheduler on Amazon

You can use Instance Scheduler on Amazon to automate the starting and stopping of EC2 instances. For more information, see How do I use Instance Scheduler with CloudFormation to schedule EC2 instances? Note that additional charges apply.

Amazon Lambda and an Amazon EventBridge rule

You can use Lambda and an EventBridge rule to stop and start your instances on a schedule. For more information, see How do I stop and start Amazon EC2 instances at regular intervals using Lambda?

Amazon EC2 Auto Scaling

To ensure you have the correct number of Amazon EC2 instances available to handle the load for an application, create Auto Scaling groups. Amazon EC2 Auto Scaling ensures that your application always has the right capacity to handle the traffic demand, and saves costs by launching instances only when they are needed. Note that Amazon EC2 Auto Scaling terminates, rather than stops, unneeded instances. To set up Auto Scaling groups, see Get started with Amazon EC2 Auto Scaling.

What happens when you stop an instance

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

When you stop an instance, the following is 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.

When you stop an instance, the following is 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.

When you stop an instance, the following persists:
  • 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 and terminate your Mac instance.

What happens when you start an instance

When you start an instance, changes are registered at the instance level.

When you start an EC2 instance, the following occurs:
  • 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.

Modify a stopped instance

When an instance is stopped, you can treat its root volume like any other volume, and modify it (for example, repair file system problems or update software).

You can modify the following attributes of an instance only when it is stopped:
  • Instance type

  • User data

  • Kernel

  • RAM disk

If you try to modify these attributes while the instance is running, Amazon EC2 returns the IncorrectInstanceState error.

You can change the following attributes of a stopped instance using the Amazon EC2 console or the Amazon CLI:
  • Instance type

  • User data

  • EBS-optimization

Modification of the following attributes using the Amazon EC2 console is not supported:
  • DeleteOnTermination

  • Kernel

  • RAM disk

Modify an instance attribute

You can modify an instance attribute using the Amazon EC2 console or the command line.

Console
To modify the following in the Amazon Web Services Management Console See the following resource

Instance type

Change the instance type

User data

User data and the console

EBS–optimization

Modifying EBS–Optimization

The DeleteOnTermination attribute of the root volume

Update the block device mapping of a running instance. You are not required to stop the instance to change this attribute.

Command line
Modify an instance attribute using the command line

You can use the following commands to modify instance attributes. For more information about these command line interfaces see Access Amazon EC2.

Modify the root volume of an instance

You can modify the root volume of an instance by performing the following steps.

  1. Detach the volume from the stopped instance.

  2. Attach the volume to a running instance.

  3. Modify the volume.

  4. Detach the volume from the running instance.

  5. Reattach the volume to the stopped instance.

Make sure that you reattach the root volume using the storage device name specified as the root device in the block device mapping for the instance. For detailed steps on how to detach and attach a volume to an instance, see Detach an Amazon EBS volume from a Linux instance and Attach an Amazon EBS volume to an instance. For more help with specifying block device mappings, see Block device mappings.

Enable stop protection

To prevent an instance from being accidentally stopped, you can enable stop protection for the instance. Stop protection also protects your instance from accidental termination.

The DisableApiStop attribute of the Amazon EC2 ModifyInstanceAttribute API controls whether the instance can be stopped by using the Amazon EC2 console, the Amazon CLI, or the Amazon EC2 API. You can set the value of this attribute when you launch the instance, while the instance is running, or while the instance is stopped.

Limitations
  • Enabling stop protection does not prevent you from accidentally stopping an instance by initiating a shutdown from the instance using an operating system command such as shutdown or poweroff.

  • Enabling stop protection does not prevent Amazon from stopping the instance when there is a scheduled event to stop the instance.

  • Enabling stop protection does not prevent Amazon EC2 Auto Scaling from terminating an instance when the instance is unhealthy or during scale-in events. You can control whether an Auto Scaling group can terminate a particular instance when scaling in by using instance scale-in protection.

  • Stop protection not only prevents your instance from being accidentally stopped, but also from accidental termination when using the console, Amazon CLI, or API. However, it does not automatically set the DisableApiTermination attribute. Note that when the DisableApiStop attribute is set to false, the DisableApiTermination attribute setting determines whether the instance can be terminated using the console, Amazon CLI, or API. For more information see Terminate your instance.

  • You can't enable stop protection for instance store-backed instances.

  • You can't enable stop protection for Spot Instances.

  • The Amazon EC2 API follows an eventual consistency model when you enable or disable stop protection. This means that the result of running commands to set the stop protection attribute might not be immediately visible to all subsequent commands you run. For more information, see Eventual consistency in the Amazon EC2 API Reference.

Enable stop protection for an instance at launch

You can enable stop protection for an instance when launching the instance using one of the following methods.

Console
To enable stop protection for an instance at launch
  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. On the dashboard, choose Launch instance.

  3. Configure your instance in the new launch instance wizard.

  4. In the wizard, enable stop protection by choosing Enable for Stop protection under Advanced details.

Amazon CLI
To enable stop protection for an instance at launch

Use the run-instances Amazon CLI command to launch the instance, and specify the disable-api-stop parameter.

aws ec2 run-instances \ --image-id ami-a1b2c3d4e5example \ --instance-type t3.micro \ --key-name MyKeyPair \ --disable-api-stop \ ...

Enable stop protection for a running or stopped instance

You can enable stop protection for an instance while the instance is running or stopped using one of the following methods.

Console
To enable stop protection for a running or stopped instance
  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. In the left navigation pane, choose Instances.

  3. Select the instance, and then choose Actions>Instance settings>Change stop protection.

  4. Select the Enable check box, and then choose Save.

Amazon CLI
To enable stop protection for a running or stopped instance

Use the modify-instance-attribute Amazon CLI command and specify the disable-api-stop parameter.

aws ec2 modify-instance-attribute \ --instance-id i-1234567890abcdef0 \ --disable-api-stop

Disable stop protection for a running or stopped instance

You can disable stop protection for a running or stopped instance using one of the following methods.

Console
To disable stop protection for a running or stopped instance
  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. In the left navigation pane, choose Instances.

  3. Select the instance, and then choose Actions, Instance settings, Change stop protection.

  4. Clear the Enable check box, and then choose Save.

Amazon CLI
To disable stop protection for a running or stopped instance

Use the modify-instance-attribute Amazon CLI command and specify the no-disable-api-stop parameter.

aws ec2 modify-instance-attribute \ --instance-id i-1234567890abcdef0 \ --no-disable-api-stop

Test application response to stop and start

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

Troubleshoot stopping your instance

If you stopped an Amazon EBS-backed instance and it appears "stuck" in the stopping state, you can forcibly stop it. For more information, see Troubleshoot stopping your instance.