This topic describes how to call the CreateSecurityGroup operation by using Alibaba Cloud 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 denied. We recommend that you read the description of the operation before you call the operation. 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 VPC.
    In this example, the VPC name is used to query the ID of the VPC.
    aliyun vpc DescribeVpcs --RegionId cn-hangzhou --VpcName demoname --output cols=Vpcs.Vpc[].VpcId
    Sample response:
    Vpcs.Vpc[].VpcId
    ----------------
    [vpc-bp1vwnn14rqpyiczj****]
  2. Create a security group in the VPC.
    aliyun ecs CreateSecurityGroup --RegionId cn-hangzhou --Description demo --SecurityGroupName demo --VpcId vpc-bp1vwnn14rqpyiczj**** --SecurityGroupType normal

Result

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