This topic describes how to call the DeleteSnapshot operation by using Alibaba Cloud 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 and then the creation task is canceled. We recommend that you read the description of the operation before you call the operation. For more information, see DeleteSnapshot.

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, the instance name is used to query the ID of the instance.

    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 IDs of snapshots of the instance.
    aliyun ecs DescribeSnapshots --RegionId cn-hangzhou --InstanceId i-bp11txjbrek6h6sv**** --Status all --SnapshotType user --output cols=SnapshotId,Status rows=Snapshots.Snapshot[]
    Note You can delete a snapshot only if the snapshot is in the Accomplished state.
    Sample response:
    SnapshotId             | Status
    ----------             | ------
    s-bp15k4ho3tb8phjr**** | accomplished
  3. Delete the s-bp15k4ho3tb8phjr**** snapshot.
    aliyun ecs DeleteSnapshot --SnapshotId s-bp15k4ho3tb8phjr**** --Force false

Result

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