Creates a policy.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreatePolicy

The operation that you want to perform. Set the value to CreatePolicy.

PolicyDocument String Yes { "Statement": [{ "Action": ["oss:*"], "Effect": "Allow", "Resource": ["acs:oss:*:*:*"]}], "Version": "1"}

The document of the policy.

The document must be 1 to 2,048 characters in length.

PolicyName String Yes OSS-Administrator

The name of the policy.

The name must be 1 to 128 characters in length and can contain letters, digits, and hyphens (-).

Description String No OSS administrator

The description of the policy.

The description must be 1 to 1,024 characters in length.

Response parameters

Parameter Type Example Description
Policy Struct

The information of the policy.

CreateDate String 2015-01-23T12:33:18Z

The time when the policy was created.

DefaultVersion String v1

The version number of the policy. Default value: v1.

Description String OSS administrator

The description of the policy.

PolicyName String OSS-Administrator

The name of the policy.

PolicyType String Custom

The type of the policy. Valid values:

  • Custom: custom policy
  • System: system policy
RequestId String 9B34724D-54B0-4A51-B34D-4512372FE1BE

The ID of the request.

Examples

Sample requests

https://resourcemanager.aliyuncs.com/?Action=CreatePolicy
&PolicyDocument={ "Statement": [{ "Action": ["oss:*"], "Effect": "Allow", "Resource": ["acs:oss:*:*:*"]}], "Version": "1"}
&PolicyName=OSS-Administrator
&<Common request parameters>

Sample success responses

XML format

<CreatePolicyResponse>
      <RequestId>9B34724D-54B0-4A51-B34D-4512372FE1BE</RequestId>
      <Policy>
            <PolicyName>OSS-Administrator</PolicyName>
            <PolicyType>Custom</PolicyType>
            <Description>OSS administrator</Description>
            <DefaultVersion>v1</DefaultVersion>
            <CreateDate>2015-01-23T12:33:18Z</CreateDate>
      </Policy>
</CreatePolicyResponse>

JSON format

{
    "RequestId": "9B34724D-54B0-4A51-B34D-4512372FE1BE",
    "Policy": {
        "PolicyName": "OSS-Administrator",
        "PolicyType": "Custom",
        "Description": "OSS administrator",
        "DefaultVersion": "v1",
        "CreateDate": "2015-01-23T12:33:18Z"
    }
}

Error codes

HttpCode Error code Error message Description
400 InvalidParameter.PolicyName.InvalidChars The policy name contains invalid characters. It must only contain upper or lower case letters, numbers, and dash (-). The error message returned because the policy name contains invalid characters. The policy name can contain only letters, digits, and hyphens (-).
400 InvalidParameter.PolicyName.Length The length of the policy name is invalid. It must be 1 to 128 characters in length. The error message returned because the length of the policy name is invalid. The policy name must be 1 to 128 characters in length.
400 InvalidParameter.PolicyDocument.Length The maximum length of the policy document is exceeded. It must not exceed 2048 characters. The error message returned because the length of the policy document has exceeded the upper limit. The policy document must be 1 to 2,048 characters in length.
400 InvalidParameter.Description.Length The maximum length of the description is exceeded. It must not exceed 1024 characters. The error message returned because the length of the policy description has exceeded the upper limit. The policy description must be 1 to 1,024 characters in length.
409 MalformedPolicyDocument The policy format is invalid. The error message returned because the policy format is invalid.
409 EntityAlreadyExists.Policy The policy already exists. The error message returned because the policy already exists.
409 LimitExceeded.Policy The maximum number of policies is exceeded. The error message returned because the number of policies has exceeded the upper limit.

For a list of error codes, visit the API Error Center.