# Delete a machine image

Delete a machine image's snapshot so it stops costing storage; the image's record stays as deleted.

Replace _ewi-1a2b3c4d_ with your image's id.

**Warning:**
The snapshot is deleted and cannot be recovered. Nothing can be launched from the image afterwards.

## Prerequisites

- Permission for `ec2:DeregisterImage`.
- In the console, also `ec2:DescribeImages` to open **Images** (without it the page says "Access
  denied").
- An image of yours. A platform base image is refused with `409` ("… is a platform base image
  shared by every organization, not a snapshot of yours, so it cannot be removed. …"). An id
  that is not one of your images answers `404` "Image not found".

## Delete the image

**Console**
1. Open **Compute**, then **Images**, and choose the image's row. Its details open in a side
   panel.
2. Under **Delete this image**, choose **Delete image**.
3. In the confirmation dialog, enter the image name.
4. Choose **Delete image**. The image's state changes to **Deleted**.

**CLI**
```sh
dcloud ec2 machine-images deregister ewi-1a2b3c4d
```

**API**
```http
DELETE /ec2/api/machine-images/ewi-1a2b3c4d
```

**Terraform**
Remove the `dcloud_machine_image` resource and run `terraform apply`.

## Result

The snapshot is deleted, which stops the storage charge, and the image moves to state
`deregistered` (**Deleted** in the console). The record stays: instances built from it still name
it, and so do invoice lines already written. Instances already running are untouched. Deleting an
image that is already deleted answers the same. If the provider cannot delete the snapshot, the
request answers `502` "The snapshot is still at the provider and still billing: …" (for an image on
your own hosts, "The image is still on the hosts: …") and the image is unchanged; try again.

## Related

- [Create a machine image](create-a-machine-image.md)
- `ec2.machine-images.deregister` · `dcloud ec2 machine-images deregister` · `dcloud_machine_image`
