This topic describes how to call the DeleteSecurityGroup operation by using Alibaba Cloud command-line interface (CLI) to delete a security group.

Background information

You can call the DeleteSecurityGroup operation to delete a security group. For more information, see DeleteSecurityGroup.

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.

Note Before you delete a security group, make sure that no ECS instances exist in it and that the security group is not authorized by other security groups. Otherwise, the request for calling DeleteSecurityGroup fails.

Request examples

  1. Call the DescribeSecurityGroups operation to query the ID of the security group that you want to delete.

    In this example, query the ID of the security group by using the security group name namedemo.

    aliyun ecs DescribeSecurityGroups --RegionId cn-hangzhou --SecurityGroupName namedemo --DryRun false --output cols=SecurityGroupId rows=SecurityGroups.SecurityGroup[]
    Sample response:
    SecurityGroupId
    ---------------
    sg-bp1i4c0xgqxadew2****
  2. Delete security group sg-bp1i4c0xgqxadew2****.
    aliyun ecs DeleteSecurityGroup --RegionId cn-hangzhou --SecurityGroupId sg-bp1i4c0xgqxadew2****

Result

{
        "RequestId": "B0B04008-0685-4EC8-9468-F2FB44981FA7"
}