创建安全组
更新时间:2026-06-22
该接口用于创建安全组以及安全组规则。
- 同一安全组中的规则以remark、protocol、direction、portRange、sourceIp|destIp、sourceGroupId|destGroupId唯一性索引,重复记录会报409错误。
- protocol的取值(tcp|udp|icmp),默认值为空,代表all。
API Explorer
去调试
您可以在 API Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,API Explorer 可以自动生成 SDK 代码示例。
请求结构
Plain Text
1POST /v{version}/securityGroup HTTP/1.1
2Host: bcc.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "name" : name,
7 "desc" : desc,
8 "vpcId" : vpcId,
9 "tags" : [
10 {
11 "tagKey" : tagKey,
12 "tagValue" : tagValue
13 }
14 ],
15 "rules" : [rule]
16}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| version | String | 是 | URL参数 | API版本号 |
| name | String | 是 | RequestBody参数 | 安全组名称,支持大小写字母、数字、中文以及-_ /.特殊字符,必须以字母开头,长度1-65 |
| desc | String | 否 | RequestBody参数 | 安全组描述信息 |
| vpcId | String | 否 | RequestBody参数 | 安全组所属的vpcId |
| tags | List<Tag> | 否 | RequestBody参数 | 标签列表 |
| rules | List<String> | 是 | RequestBody参数 | 安全组规则列表 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| securityGroupId | String | 已创建的安全组ID |
错误码
| 错误码 | 错误描述 | HTTP状态码 | 中文解释 |
|---|---|---|---|
| SecurityGroup.RuleRemarkTooLong | Security group description is too long. | 400 | 安全组规则备注字段超限 |
| BadRequest | protocol is invalid. | 400 | 协议类型错误 |
| SecurityGroup.RulePortOrderInvalid | The order of security group rule port is incorrect. | 400 | 安全组规则端口顺序不正确 |
| SecurityGroup.RulePortRangeInvalid | The value of security group rule port is exceeded. | 400 | 安全组规则的端口数字超出允许范围 |
| SecurityGroup.RulePortInvalid | The value of security group rule port must be number. | 400 | 安全组规则端口非数字 |
| SecurityGroup.RuleCIDRAddressError | Security group rule ip(cidr) address is incorrect. | 400 | 安全组规则源(目标)地址错误 |
| SecurityGroup.RuleDirectionError | Security group rule direction is incorrect. | 400 | 安全组规则direction不符合 |
| SecurityGroup.RuleDuplicated | Security group rule is duplicated. | 409 | 安全组规则重复 |
| SecurityGroup.RuleNumberExceededLimit | Security groups that contain rule number exceed limit. | 413 | 安全组所包含规则数目超限 |
请求示例
Plain Text
1POST /v2/securityGroup HTTP/1.1
2Host: bcc.bj.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2015-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
4
5{
6 "name": "test-security-group",
7 "desc": "create a security group for api doc",
8 "vpcId": "vpc-uxjret8rnv",
9 "rules": [
10 {
11 "remark": "备注",
12 "protocol": "tcp",
13 "portRange": "1-65535",
14 "direction": "ingress",
15 "sourceIp": "",
16 "sourceGroupId": ""
17 },
18 {
19 "remark": "全部协议",
20 "protocol": "",
21 "portRange": "",
22 "direction": "egress",
23 "destIp": "",
24 "destGroupId": ""
25 }
26 ]
27}
返回示例
Plain Text
1HTTP/1.1 200 OK
2x-bce-request-id: 1214cca7-4ad5-451d-9215-71cb844c0a50
3Date: Wed, 03 Dec 2014 06:42:19 GMT
4Content-Type: application/json;charset=UTF-8
5Server: BWS
6
7{
8 "securityGroupId": "g-nky7qeom"
9}
评价此篇文章
