# Stop, start or reboot an instance

Power an instance off, on again, shut it down cleanly or reboot it.

Replace _i-3f9a2c07_ with your instance's id. `stop` cuts the power; `shutdown` asks the guest OS
to halt cleanly; `reboot` restarts the machine.

## Prerequisites

- In the console, also `ec2:DescribeInstances` to open the instance's page (without it the page is
  not found).
- Permission for `ec2:StartInstances` (start), `ec2:StopInstances` (stop and shutdown) or
  `ec2:RebootInstances` (reboot).
- `start` needs the instance `stopped` (or `suspended`); `stop`, `shutdown` and `reboot` need it
  `running`. Otherwise the request is refused with `400` "Cannot start instance in state: …"
  ("Cannot stop instance in state: …" for `stop` and `shutdown`, "Cannot reboot instance in state:
  …" for `reboot`). In the console the action is unavailable, with the reason, until the instance
  is in that state.
- An instance that is a node of a Kubernetes cluster is refused with `409` "This instance is node …
  of the Kubernetes cluster …. Scale or delete its node group instead."
- An instance on your own hosts whose machine does not exist yet is refused with `409` "Instance is
  not yet backed by a machine".

## Change the power state

**Console**
1. Open the instance. The header shows **Stop** while it runs and **Start** while it is stopped.
2. Choose **Stop** or **Start**, or open the **⋯** menu and choose **Reboot**.
3. For **Stop** and **Reboot**, choose **Stop** or **Reboot** in the dialog that asks to confirm.
   **Start** asks nothing.

The console has no separate shutdown; its **Stop** cuts the power.

**CLI**
```sh
dcloud ec2 instances stop i-3f9a2c07
dcloud ec2 instances shutdown i-3f9a2c07
dcloud ec2 instances start i-3f9a2c07
dcloud ec2 instances reboot i-3f9a2c07
```

**API**
```http
PATCH /ec2/api/instances/i-3f9a2c07
{ "action": "reboot" }
```

`action` is `start`, `stop`, `shutdown` or `reboot`.

## Result

The answer comes at once with the transitional state (`pending`, `stopping` or `rebooting`); the
final state follows when the provider is done (`running` or `stopped`). If the action fails, the
instance returns to its previous state and the page shows the error. A stopped instance keeps its
disk, addresses and volumes. Instance hours are billed only while the instance is `running`, so a
stopped instance costs nothing per hour; its volumes are still billed, and its snapshots and
elastic IPs are still metered.

A machine of an auto scaling group that you stop here is replaced by the group.

## Related

- [Instance lifecycle](instance-lifecycle.md)
- `ec2.instances.stop` · `dcloud ec2 instances start` · `dcloud_instance`
