

# Stop and start Amazon EC2 instances
<a name="Stop_Start"></a>

You can stop and start your instance if it has an Amazon EBS volume as its root volume. 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](schedevents_actions_retire.md).

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](terminating-instances.md). If you want to hibernate an instance to save the contents from the instance memory (RAM), see [Hibernate your Amazon EC2 instance](Hibernate.md). For distinctions between instance lifecycle actions, see [Differences between instance states](ec2-instance-lifecycle.md#lifecycle-differences).

**Topics**
+ [How it works](how-ec2-instance-stop-start-works.md)
+ [

# Methods for stopping an instance
](instance-stop-methods.md)
+ [Manually stop and start](#starting-stopping-instances)
+ [Automatically stop and start](#stop-start-ec2-instances-on-a-schedule)
+ [Find running and stopped instances](#find-running-and-stopped-instances-in-globalview)
+ [

## Find the initial and most recent launch times
](#find-initial-launch-time)
+ [Enable stop protection](ec2-stop-protection.md)

# How EC2 instance stop and start works
<a name="how-ec2-instance-stop-start-works"></a>

When you stop an Amazon EC2 instance, changes are registered at the operating system (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.

**Topics**
+ [

## What happens when you stop an instance
](#what-happens-stop)
+ [

## What happens when you start an instance
](#what-happens-start)
+ [

## Test application response to stop and start
](#test-stop-start-instance)
+ [

## Costs related to instance stop and start
](#ec2-stop-start-costs)

## What happens when you stop an instance
<a name="what-happens-stop"></a>

The following describes what typically happens when you stop an instance using the default stop method. Note that some aspects might vary depending on which [stop method](instance-stop-methods.md) you use.

**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 OS shutdown is triggered by the ACPI shutdown button press event from the hypervisor.
+ ACPI shutdown is initiated.
+ The instance shuts down when the graceful OS 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 state 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 instances in an Auto Scaling group](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-health-checks.html) 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](ec2launch-v2.md).

**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](elastic-ip-addresses-eip.md) with your instance.

**Resources that persist**
+ Any attached Amazon EBS root and data volumes.
+ Data stored on the Amazon EBS volumes.
+ Any attached [network interfaces](using-eni.md).

  A network interface includes the following resources, which also persist:
  + 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](elastic-ip-addresses-eip.md#eip-pricing).

The following diagram illustrates what persists and what is lost when an EC2 instance is stopped. The diagram is divided into three parts: the first part, labeled **Running EC2 instance**, shows the instance in the `running` state with its resources. The second part, labeled **Stopped EC2 instance**, shows the instance in the `stopped` state with the resources that persist. The third part, labeled **Lost**, shows the resources that are lost when the instance is stopped.

![\[The public IPv4 address, RAM, and instance storage data are lost when an instance is stopped.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/stop-instance.png)


For information about what happens when you stop a Mac instance, see [Stop or terminate your Amazon EC2 Mac instance](mac-instance-stop.md).

## What happens when you start an instance
<a name="what-happens-start"></a>
+ 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](dedicated-hosts-understanding.md) configuration, it remains on the current host).
+ The associated EBS volumes and network interfaces are reattached to the instance.
+ Amazon EC2 assigns a new public IPv4 address to the instance if the instance is configured to receive a public IPv4 address, unless it has a secondary network interface or a secondary private IPv4 address that is associated with an Elastic IP address.
+ If you stop an instance in a placement group and then start it again, it still runs in the placement group. However, the start fails if there isn't enough capacity for the instance. If you receive a capacity error when starting an instance in a placement group that already has running instances, stop all the instances in the placement group and start them all again. Starting the instances may migrate them to hardware that has capacity for all of the requested instances.

## Test application response to stop and start
<a name="test-stop-start-instance"></a>

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](https://docs.aws.amazon.com/fis/latest/userguide/what-is.html).

## Costs related to instance stop and start
<a name="ec2-stop-start-costs"></a>

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.

# Methods for stopping an instance
<a name="instance-stop-methods"></a>

There are four ways to perform a user-initiated stop: default stop, stop with skip OS shutdown, force stop, and force stop with skip OS shutdown. The following table compares the key differences between the stop methods:


| Stop method | Key purpose | Use case | CLI command | 
| --- | --- | --- | --- | 
| Default stop | Normal instance shutdown with attempted graceful OS shutdown. | Typical instance stop. |  <pre>aws ec2 stop-instances \<br />--instance-id i-1234567890abcdef0</pre>  | 
| Stop with skip OS shutdown | Bypasses the graceful OS shutdown when stopping an instance. | When bypassing graceful OS shutdown is required. | <pre>aws ec2 stop-instances \<br />--instance-id i-1234567890abcdef0 \<br />--skip-os-shutdown</pre> | 
| Force stop | Handles stuck instances. Attempts a default stop first; if instance fails to stop, then forcibly stops the instance. | When instance is stuck in stopping state. | <pre>aws ec2 stop-instances \<br />--instance-id i-1234567890abcdef0 \<br />--force</pre> | 
| Force stop with skip OS shutdown | Force stops and bypasses the graceful OS shutdown when stopping an instance. | When force stop and bypassing graceful OS shutdown is required. | <pre>aws ec2 stop-instances \<br />--instance-id i-1234567890abcdef0 \<br />--force \<br />--skip-os-shutdown</pre> | 

For instructions on how to use each method, see the following:
+ [Stop an instance with a graceful OS shutdown](Stop_Start.md#stop-instance-with-graceful-os-shutdown)
+ [Stop an instance and bypass the graceful OS shutdown](Stop_Start.md#stop-instance-bypass-graceful-os-shutdown)
+ [Force stop an instance](TroubleshootingInstancesStopping.md#force-stop-instance)

**Topics**
+ [

## Default stop
](#ec2-instance-default-stop)
+ [

## Stop with skip OS shutdown
](#ec2-instance-stop-with-skip-os-shutdown)
+ [

## Force stop
](#ec2-instance-force-stop)
+ [

## Force stop with skip OS shutdown
](#ec2-instance-force-stop-with-skip-os-shutdown)

The following sections provide more detailed information about the four different user-initiated stop methods.

## Default stop
<a name="ec2-instance-default-stop"></a>

The default stop method is the standard way to stop an instance. When you issue the StopInstances command, the instance transitions from the `running` state, to `stopping`, and finally to `stopped`, as illustrated by the following diagram:

![\[Default stop flow\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/stop-instance-flow-1.png)


**Purpose:** Normal instance shutdown with attempted graceful OS shutdown.

**Data impact:** Preserves data on the EBS root volume and data volumes. Loses data on the instance store volume.

**When to use:** First stop attempt for typical stops.

**Note**  
If you've already attempted a stop with skip OS shutdown, a subsequent default stop attempt during the same state transition session will not perform a graceful OS shutdown. Bypassing the graceful OS shutdown is irreversible for the instance's current session.

## Stop with skip OS shutdown
<a name="ec2-instance-stop-with-skip-os-shutdown"></a>

When bypassing the graceful OS shutdown is required, the stop with skip OS shutdown method can be used to stop an instance and bypass the graceful OS shutdown, as illustrated by the following diagram:

![\[Stop with skip OS shutdown flow\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/stop-instance-flow-3.png)


**Warning**  
Bypassing the graceful OS shutdown might result in data loss or corruption (for example, memory contents not flushed to disk or loss of in-flight IOs) or skipped shutdown scripts.

**Purpose:** Bypass the graceful OS shutdown when stopping an instance.

**Data impact:** Might result in data loss or corruption. Contents of memory might not be flushed to disk and in-flight IOs might be lost. Might skip shutdown scripts.

**When to use:** When bypassing the graceful OS shutdown is required. If used while a default stop with graceful OS shutdown is in progress, the graceful OS shutdown will be bypassed.

**Note**  
Bypassing the graceful OS shutdown is irreversible for the instance's current state transition session. A subsequent default stop attempt during this session will not attempt a graceful OS shutdown. 

## Force stop
<a name="ec2-instance-force-stop"></a>

The force stop method is used to handle instances that are stuck in the `stopping` state. An instance typically becomes stuck due to an underlying hardware issue (indicated by a failed [system status check](monitoring-system-instance-status-check.md#system-status-checks)).

The force stop method first attempts a default stop. If the instance remains stuck in the `stopping` state, the `force` parameter forcibly shuts down the instance and transitions the instance to the `stopped` state, as indicated by the following diagram:

![\[Force stop flow\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/stop-instance-flow-2.png)


**Purpose:** Handles instances stuck in the `stopping` state. Attempts a default stop first. If the instance fails to stop, then forcibly shuts down the instance.

**Data impact:** Attempts a default stop first, but if force stop goes ahead, then might cause data loss or corruption. In rare cases, results in post-stop writes to EBS volumes or other shared resources.

**When to use:** Second stop attempt when an instance remains stuck after a default stop. For more information, see [Troubleshoot Amazon EC2 instance stop issues](TroubleshootingInstancesStopping.md).

## Force stop with skip OS shutdown
<a name="ec2-instance-force-stop-with-skip-os-shutdown"></a>

When force stopping and bypassing the graceful OS shutdown is required, the force stop with skip OS shutdown method can be used to bring an instance to the `stopped` state, as illustrated in the following diagram:

![\[Force stop with skip OS shutdown flow\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/stop-instance-flow-4.png)


**Purpose:** Combines force stop with bypassing a graceful OS shutdown when stopping an instance.

**Data impact:** Skip OS shutdown might result in data loss or corruption. Contents of memory might not be flushed to disk and in-flight IOs might be lost. Might skip shutdown scripts. If force stop goes ahead, then might cause additional data loss or corruption. In rare cases, results in post-stop writes to the EBS volumes or other shared resources.

**When to use:** When you want to be sure that your instance will stop and you want to bypass the graceful OS shutdown. If used while a default stop with graceful OS shutdown is in progress, the graceful OS shutdown will be bypassed.

## Manually stop and start your instances
<a name="starting-stopping-instances"></a>

You can stop and start your Amazon EBS-backed instances (instances with EBS root volumes). You can't stop and start instances with an instance store root volume.

When using the default method to stop an instance, a graceful operating system (OS) shutdown is attempted. You can bypass the graceful OS shutdown; however, this might risk data integrity. 

**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 into `HLT`, which suspends CPU operation. The instance remains running.

You can initiate a shutdown using the OS **shutdown** or **poweroff** 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](Using_ChangingInstanceInitiatedShutdownBehavior.md).

**Note**  
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 Amazon EC2 instance stop issues](TroubleshootingInstancesStopping.md).

**Topics**
+ [

### Stop an instance with a graceful OS shutdown
](#stop-instance-with-graceful-os-shutdown)
+ [

### Stop an instance and bypass the graceful OS shutdown
](#stop-instance-bypass-graceful-os-shutdown)
+ [

### Start an instance
](#start-ec2-instance)

### Stop an instance with a graceful OS shutdown
<a name="stop-instance-with-graceful-os-shutdown"></a>

You can stop an instance using the default stop method, which includes an attempt at a graceful OS shutdown. For more information, see [Default stop](instance-stop-methods.md#ec2-instance-default-stop).

------
#### [ Console ]

**To stop an instance using the default stop method**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the left navigation pane, choose **Instances**, and then select the instance.

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

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

------
#### [ AWS CLI ]

**To stop an instance using the default stop method**  
Use the [stop-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html) command.

```
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
```

------
#### [ PowerShell ]

**To stop an instance using the default stop method**  
Use the [Stop-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/Stop-EC2Instance.html) cmdlet 

```
Stop-EC2Instance -InstanceId i-1234567890abcdef0
```

------

### Stop an instance and bypass the graceful OS shutdown
<a name="stop-instance-bypass-graceful-os-shutdown"></a>

You can bypass the graceful OS shutdown when stopping an instance. For more information, see [Stop with skip OS shutdown](instance-stop-methods.md#ec2-instance-stop-with-skip-os-shutdown).

**Warning**  
Bypassing the graceful OS shutdown might result in data loss or corruption (for example, memory contents not flushed to disk or loss of in-flight IOs) or skipped shutdown scripts.

------
#### [ Console ]

**To stop an instance and bypass the graceful OS shutdown**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and select the instance.

1. Choose **Instance state**, **Stop instance**.

1. Under **Skip OS shutdown**, select the **Skip OS shutdown** checkbox. If you don't see this option in the console, it's not yet available in the console in the current Region. You can, however, access this feature using the AWS CLI or SDK, or try another Region in the console.

1. Choose **Stop**.

------
#### [ AWS CLI ]

**To stop an instance and bypass the graceful OS shutdown**  
Use the [stop-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html) command with `--skip-os-shutdown`.

```
aws ec2 stop-instances \
    --instance-ids i-1234567890abcdef0 \
    --skip-os-shutdown
```

------
#### [ PowerShell ]

**To stop an instance and bypass the graceful OS shutdown**  
Use the [Stop-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/Stop-EC2Instance.html) cmdlet with `-SkipOsShutdown $true`.

```
Stop-EC2Instance `
    -InstanceId i-1234567890abcdef0 `
    -SkipOsShutdown $true
```

------

### Start an instance
<a name="start-ec2-instance"></a>

You can start a stopped instance.

------
#### [ Console ]

**To start an instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the left navigation pane, choose **Instances**.

1. Select the instance, and choose **Instance state**, **Start instance**.

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

------
#### [ AWS CLI ]

**To start an instance**  
Use the [start-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/start-instances.html) command.

```
aws ec2 start-instances --instance-ids i-1234567890abcdef0
```

------
#### [ PowerShell ]

**To start an instance**  
Use the [Start-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/Start-EC2Instance.html) cmdlet.

```
Start-EC2Instance -InstanceId i-1234567890abcdef0
```

------

## Automatically stop and start your instances
<a name="stop-start-ec2-instances-on-a-schedule"></a>

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?](https://repost.aws/knowledge-center/stop-start-instance-scheduler) Note that [additional charges apply](https://docs.aws.amazon.com/solutions/latest/instance-scheduler-on-aws/cost.html). 

**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 use Lambda to stop and start Amazon EC2 instances at regular intervals?](https://repost.aws/knowledge-center/start-stop-lambda-eventbridge)

**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](https://docs.aws.amazon.com/autoscaling/ec2/userguide/get-started-with-ec2-auto-scaling.html).

## Find all running and stopped instances
<a name="find-running-and-stopped-instances-in-globalview"></a>

You can find all of your running and stopped instances across all AWS Regions on a single page using [Amazon EC2 Global View](https://console.aws.amazon.com/ec2globalview/home). 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 AWS Global View](global-view.md).

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](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) 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](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) 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](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Instance.html) 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](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Instance.html) 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
<a name="find-initial-launch-time"></a>

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](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) 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](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Instance.html) 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](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Instance.html) cmdlet.

```
(Get-EC2Instance -InstanceId i-1234567890abcdef0).Instances.NetworkInterfaces.Attachment.AttachTime
```

The following is example output.

```
Friday, April 19, 2024 12:47:08 AM
```

------

# Enable stop protection for your EC2 instances
<a name="ec2-stop-protection"></a>

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 [https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyInstanceAttribute.html](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyInstanceAttribute.html) API controls whether the instance can be stopped by using the Amazon EC2 console, the AWS 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.

**Considerations**
+ 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](monitoring-instances-status-check_sched.md) 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](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-protection.html). 
+ 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 the `DisableApiStop` attribute is set to `false`, the `DisableApiTermination` attribute setting determines whether the instance can be terminated using the console, AWS CLI, or API. For more information see [Terminate Amazon EC2 instances](terminating-instances.md).
+ You can't enable stop protection for an instance with an instance store root volume.
+ 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](https://docs.aws.amazon.com/ec2/latest/devguide/eventual-consistency.html) in the *Amazon EC2 Developer Guide*.

**Topics**
+ [

## Enable stop protection for an instance at launch
](#enable-stop-protection-at-launch)
+ [

## Enable stop protection for a running or stopped instance
](#enable-stop-protection-on-running-or-stopped-instance)
+ [

## Disable stop protection for a running or stopped instance
](#disable-stop-protection-on-running-or-stopped-instance)

## Enable stop protection for an instance at launch
<a name="enable-stop-protection-at-launch"></a>

You can enable stop protection for an instance when launching the instance.

------
#### [ Console ]

**To enable stop protection for an instance at launch**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. On the dashboard, choose **Launch instance**.

1. Configure your instance in the [new launch instance wizard](ec2-launch-instance-wizard.md).

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

------
#### [ AWS CLI ]

**To enable stop protection for an instance at launch**  
Use the [run-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html) command to launch the instance. Add the following parameter.

```
--disable-api-stop
```

------
#### [ PowerShell ]

**To enable stop protection for an instance at launch**  
Use the [New-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2Instance.html) cmdlet to launch the instance. Add the following parameter.

```
-DisableApiStop $true
```

------

## Enable stop protection for a running or stopped instance
<a name="enable-stop-protection-on-running-or-stopped-instance"></a>

You can enable stop protection for an instance while the instance is running or stopped.

------
#### [ Console ]

**To enable stop protection for an instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the left navigation pane, choose **Instances**.

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

1. Select the **Enable** checkbox, and then choose **Save**.

------
#### [ AWS CLI ]

**To enable stop protection for an instance**  
Use the [modify-instance-attribute](https://docs.aws.amazon.com/cli/latest/reference/ec2/modify-instance-attribute.html) command.

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

------
#### [ PowerShell ]

**To enable stop protection for an instance**  
Use the [Edit-EC2InstanceAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Edit-EC2InstanceAttribute.html) cmdlet.

```
Edit-EC2InstanceAttribute `
    -InstanceId i-1234567890abcdef0 `
    -DisableApiStop $true
```

------

## Disable stop protection for a running or stopped instance
<a name="disable-stop-protection-on-running-or-stopped-instance"></a>

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.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the left navigation pane, choose **Instances**.

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

1. Clear the **Enable** checkbox, and then choose **Save**.

------
#### [ AWS CLI ]

**To disable stop protection for a running or stopped instance**  
Use the [modify-instance-attribute](https://docs.aws.amazon.com/cli/latest/reference/ec2/modify-instance-attribute.html) command.

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

------
#### [ PowerShell ]

**To disable stop protection for an instance**  
Use the [Edit-EC2InstanceAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Edit-EC2InstanceAttribute.html) cmdlet.

```
Edit-EC2InstanceAttribute `
    -InstanceId i-1234567890abcdef0 `
    -DisableApiStop $false
```

------