This topic describes how to call the DeleteSnapshot operation by using Alibaba Cloud command-line interface (CLI) to delete the specified snapshot.

Background information

You can call the DeleteSnapshot operation to delete a snapshot. If you want to cancel a snapshot that is being created, you can also call this operation to delete the snapshot. For more information, see CreateSnapshot.

When you call an API operation through Alibaba Cloud CLI, make sure that request parameter values of different data types are in required formats. For more information, see Parameter format overview.

Request examples

  1. Call the DescribeInstances operation to query the ID of an ECS instance for which you want to delete snapshots.

    In this example, query the ID of an ECS instance by using its name.

    aliyun ecs DescribeInstances --RegionId cn-hangzhou --InstanceName demoname --output rows=Instances.Instance[] cols=InstanceId,Status
    Sample response:
    InstanceId             | Status
    ----------             | ------
    i-bp14a7xie8erwsvo**** | Running
  2. Call the DescribeSnapshots operation to query the snapshot ID in the ECS instance.
    aliyun ecs DescribeSnapshots --RegionId cn-hangzhou --InstanceId i-bp11txjbrek6h6sv84q6 --Status all --SnapshotType user --output cols=SnapshotId,Status rows=Snapshots.Snapshot[]
    Note You can delete the snapshot only if it is in the accomplished state.
    Sample response:
    SnapshotId             | Status
    ----------             | ------
    s-bp15k4ho3tb8phjr**** | accomplished
  3. Delete snapshot s-bp15k4ho3tb8phjr****.
    aliyun ecs DeleteSnapshot --SnapshotId s-bp15k4ho3tb8phjr**** --Force false


        "RequestId": "094B3E9B-AE39-4AE0-B25C-EF14560DC968"