You need to enable JavaScript to run this app.
导航
CreatePolicy - 创建策略
最近更新时间:2025.06.11 16:04:37首次发布时间:2021.02.23 10:42:33
我的收藏
有用
有用
无用
无用

创建自定义策略。

调试

请求参数

下表仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数

参数
类型
是否必填
示例值
描述
Action
String

CreatePolicy

要执行的操作,取值:CreatePolicy。

Version
String

2018-01-01

API的版本,取值:2018-01-01。

PolicyName
String

example_policy

策略名。长度1~64,支持英文、数字和+=,.@-_符号。

PolicyDocument
String

{"Statement":[{"Effect":"Allow","Action":["iam:","tag:"],"Resource":["*"]}]}

策略语法内容。语法可参考 策略语法说明

Description
String

示例策略

策略描述。长度不超过128。

返回参数

下表仅列出本接口特有的返回参数。更多信息请参见返回结构

参数
类型
示例值
描述
Policy
Object

请参考数据结构内具体参数示例值。

策略的数据结构。

请求示例

GET /?Action=CreatePolicy&Version=2018-01-01&PolicyName=name_example&PolicyDocument={"Statement":[{"Effect":"Allow","Action":["iam:*","tag:*"],"Resource":["*"]}]} HTTP/1.1
Host: iam.volcengineapi.com
X-Date: 20240912T061108Z
Authorization: HMAC-SHA256 Credential=Adfks******wekfwe/20240912/cn-beijing/iam/request, SignedHeaders=host;x-date, Signature=47a7d934ff7b37c03938******cd7b8278a40a1057690c401e92246a0e41085f


返回示例

{
  "ResponseMetadata": {
    "RequestId": "20240912141113237240205003159C07",
    "Action": "CreatePolicy",
    "Version": "2018-01-01",
    "Service": "iam",
    "Region": "cn-beijing"
  },
  "Result": {
    "Policy": {
      "PolicyName": "example_policy",
      "PolicyTrn": "trn:iam::2000000000:policy/example_policy",
      "PolicyType": "Custom",
      "Description": "示例策略",
      "PolicyDocument": "{"Statement":[{"Effect":"Allow","Action":["iam:*","tag:*"],"Resource":["*"]}]}",
      "Category": "",
      "AttachmentCount": "0",
      "IsServiceRolePolicy": 0,
      "CreateDate": "20240912T061318Z",
      "UpdateDate": "20240912T061318Z"
    }
  }
}

错误码

下表为您列举了该接口与业务逻辑相关的错误码。公共错误码请参见公共错误码文档。

状态码
错误码
错误信息
说明
400
InvalidPolicyName

Invalid PolicyName '%s', err: '%s'

400
MissingPolicyDocument

Missing policy document

400
InvalidParameter

The parameter '%s' is invalid

策略语法不正确或存在服务不支持某些策略表达。查看帮助文档解决:https://www.volcengine.com/docs/6257/1274335

400
InvalidParameter.Description

The specified parameter "Description" is invalid.

描述不合法。

400
InvalidParameter.PolicyName

The specified parameter "PolicyName" is invalid.

策略名不合法。

400
InvalidPolicy.Length

The document string exceeds the maximum allowed length of 6144 characters.

策略长度超限。

400
ParameterNotFound

Parameter 'PolicyDocument' is not found.

参数缺失。

400
InvalidPolicy.Structure

Document is not a valid JSON string.

策略语法不符合JSON格式。

409
PolicyAlreadyExist

Policy '%s' already exists