Stop and start Amazon EC2 instances (original) (raw)
You can stop and start your instance if it has an Amazon EBS volume as its root device. When you stop an instance, it shuts down. When you start an instance, it is typically migrated to a new underlying host computer and assigned a new public IPv4 address.
An instance stop can be user-initiated (where you manually stop the instance) or initiated by AWS (in response to a scheduled stop event when AWS detects irreparable failure of the underlying host for your instance).
For user-initiated stops, we recommend using the Amazon EC2 console, CLI, or API instead of running the operating system stop command from your instance. When using Amazon EC2, if the instance does not cleanly shut down within a few minutes, Amazon EC2 performs a hard shut down. Furthermore, AWS CloudTrail creates an API record of when your instance was stopped.
This topic describes how to perform a user-initiated stop. For information about a stop performed by AWS, see Manage Amazon EC2 instances scheduled to stop or retire.
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 Amazon EC2 instances. 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 instance states.
Contents
- How it works
- Manually stop and start
- Automatically stop and start
- Find running and stopped instances
- Find the initial and most recent launch times
- Enable stop protection
Manually stop and start your instances
You can stop and start your Amazon EBS-backed instances (instances with EBS root devices). You can't stop and start instances with instance store root device.
Warning
When you stop an instance, the data on any instance store volumes is erased. Before you stop an instance, verify that you've copied any data that you need from the instance store volumes to persistent storage, such as Amazon EBS or Amazon S3.
[Linux instances] 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 intoHLT
, which suspends CPU operation. The instance remains running.
You can initiate a shutdown using the OS shutdown orpoweroff commands. When you use an OS command, the instance stops by default. You can change this behavior. For more information, see Change instance initiated shutdown behavior.
Console
To stop and start an Amazon EBS-backed instance
- Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
- In the left navigation pane, choose Instances, and then select the instance.
- 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.
- When prompted for confirmation, choose Stop. It can take a few minutes for the instance to stop.
- To start a stopped instance, select the instance, and chooseInstance state, Start instance.
- It can take a few minutes for the instance to enter the
running
state. - If you stopped an Amazon EBS-backed instance and it appears "stuck" in the
stopping
state, you can forcibly stop it. For more information, seeTroubleshoot Amazon EC2 instance stop issues.
AWS CLI
To stop an instance
Use the stop-instances command.
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
To start an instance
Use the start-instances command.
aws ec2 start-instances --instance-ids i-1234567890abcdef0
PowerShell
To stop an instance
Use the Stop-EC2Instance cmdlet.
Stop-EC2Instance -InstanceId i-1234567890abcdef0
To start an instance
Use the Start-EC2Instance cmdlet.
Start-EC2Instance -InstanceId i-1234567890abcdef0
Automatically stop and start your instances
You can automate stopping and starting instances with the following services:
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. This capability is especially useful for taking inventory and finding forgotten instances. For information about how to use Global View, see View resources across Regions using Amazon EC2 Global View.
Alternatively, you can run a command or cmdlet in each Region where you have instances.
AWS CLI
To get the number of EC2 instances in a Region
Use the following describe-instances command to count the instances in the current Region. You must run this command in each Region where you have instances.
aws ec2 describe-instances \
--region us-east-2 \
--query "length(Reservations[].Instances[])"
The following is example output.
27
To get summary info about your EC2 instances in a Region
Use the following describe-instances command. You must run this command in each Region where you have instances.
>aws ec2 describe-instances \
--region us-east-2 \
--query "Reservations[].Instances[].[InstanceId,InstanceType,PrivateIpAddress]" \
--output table
The following is example output.
---------------------------------------------------------
| DescribeInstances |
+---------------------+---------------+-----------------+
| i-0e3e777f4362f1bf7| t2.micro | 10.0.12.9 |
| i-09453945dcf1529e9| t2.micro | 10.0.143.213 |
| i-08fd74f3f1595fdbd| m7i.4xlarge | 10.0.1.103 |
+---------------------+---------------+-----------------+
PowerShell
To get the number of EC2 instances in a Region
Use the Get-EC2Instance cmdlet.
(Get-EC2Instance -Region us-east-2).Instances.Length
The following is example output.
27
To get summary info about your EC2 instances in a Region
Use the Get-EC2Instance cmdlet. You must run this command in each Region where you have instances.
(Get-EC2Instance).Instances | Select InstanceId, InstanceType, PrivateIpAddress
The following is example output.
InstanceId InstanceType PrivateIpAddress
---------- ------------ ----------------
i-0e3e777f4362f1bf7 t2.micro 10.0.12.9
i-09453945dcf1529e9 t2.micro 10.0.143.213
i-08fd74f3f1595fdbd m7i.4xlarge 10.0.1.103
Find the initial and most recent launch times
When you describe an instance, the launch time for the instance is its most recent launch time. After you stop and start an instance, the launch time reflects the new instance start time. To find the initial launch time for an instance, even after stopping and starting it, view the time at which the primary network interface was attached to the instance.
Console
To find the most recent launch time
Select the instance and find Launch time under Instance details on the Details tab.
To find the initial launch time
Select the instance and find the primary network interface (device index is 0) under Network interfaces on the Networking tab.
AWS CLI
To find the initial and most recent launch times
Use the following describe-instances command to display both the initial launch time and the most recent launch time for the specified instance.
aws ec2 describe-instances \
--instance-id i-1234567890abcdef0 \
--query 'Reservations[].Instances[].{InstanceID:InstanceId,InitialLaunch:NetworkInterfaces[0].Attachment.AttachTime,LastLaunch:LaunchTime}'
The following is example output.
[
{
"InstanceID": "i-1234567890abcdef0",
"InitialLaunch": "2024-04-19T00:47:08+00:00",
"LastLaunch": "2024-05-27T06:24:06+00:00"
}
]
PowerShell
To find the most recent launch time
Use the Get-EC2Instance cmdlet.
(Get-EC2Instance -InstanceId i-1234567890abcdef0).Instances.LaunchTime
The following is example output.
Monday, May 27, 2024 6:24:06 AM
To find the initial launch time
Use the Get-EC2Instance cmdlet.
(Get-EC2Instance -InstanceId i-1234567890abcdef0).Instances.NetworkInterfaces.Attachment.AttachTime
The following is example output.
Friday, April 19, 2024 12:47:08 AM