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 Amazon EC2 instance. For distinctions between instance lifecycle actions, see Differences between reboot, stop, hibernate, and terminate.
AWS 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 AWS, 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.
Topics
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 AWS Regions on a
single page using 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 AWS CLI.
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.
Automatically stop and start your instances
You can automate stopping and starting instances with the following services:
- Instance Scheduler on AWS
-
You can use Instance Scheduler on AWS 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. - AWS 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 thenstopped
. -
[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 becomesimpaired
, 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 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 Configure a Windows instance using EC2Launch v2.
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 AWS 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.
Modify the root volume of an instance
You can modify the root volume of an instance by performing the following steps.
-
Detach the volume from the stopped instance.
-
Attach the volume to a running instance.
-
Modify the volume.
-
Detach the volume from the running instance.
-
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 more information about 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
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 AWS 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, AWS CLI, or API. However, it does not automatically set the
DisableApiTermination
attribute. Note that when theDisableApiStop
attribute is set tofalse
, theDisableApiTermination
attribute setting determines whether the instance can be terminated using the console, AWS 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.
Stop protection tasks
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.
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.
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.
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.
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.