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

Background information

You can call the CreateSecurityGroup operation to create a security group. For a newly created security group, only ECS instances in the security group can access each other by default. Access requests to the security group from outside are restricted. For more information, see CreateSecurityGroup.

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 DescribeVpcs operation to query the ID of a Virtual Private Cloud (VPC).
    In this example, query the ID of a VPC by its name.
    aliyun vpc DescribeVpcs --RegionId cn-hangzhou --VpcName demoname --output cols=Vpcs.Vpc[].VpcId
    Sample response:
  2. Create a security group of the VPC type.
    aliyun ecs CreateSecurityGroup --RegionId cn-hangzhou --Description demo --SecurityGroupName demo --VpcId vpc-bp1vwnn14rqpyiczj**** --SecurityGroupType normal


        "SecurityGroupId": "sg-bp1hhwq52iu5j59f****",
        "RequestId": "8C79B3F8-5CAF-4DA0-8274-972ED1954ABA"