Creates a custom policy.

For more information about policies, see Policy overview.

This topic provides an example on how to create a custom policy to query Elastic Compute Service (ECS) instances in a specific region.

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.

PolicyName String Yes View-ECS-instances-in-a-specific-region

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 Query ECS instances in a specific region

The description of the policy.

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

PolicyDocument String Yes null

The content of the policy.

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

For more information about policy elements and sample policies, see Policy elements and Overview of sample policies.

Response parameters

Parameter Type Example Description
Policy Object

The information about the policy.

DefaultVersion String v1

The version of the policy. Default value: v1.

Description String Query ECS instances in a specific region.

The description of the policy.

PolicyName String View-ECS-instances-in-a-specific-region

The name of the policy.

CreateDate String 2021-10-13T02:46:57Z

The time when the policy was created.

PolicyType String Custom

The type of the policy. Valid values:

  • Custom: custom policy
  • System: system policy
RequestId String BA34C54A-C2B1-5A65-B6B0-B5842C1DB4DA

The ID of the request.

Examples

Sample requests

https://ram.aliyuncs.com/?Action=CreatePolicy
&PolicyName=View-ECS-instances-in-a-specific-region
&Description=Query ECS instances in a specific region
&PolicyDocument={"Statement": [{"Effect": "Allow","Action": "ecs:Describe*","Resource": "acs:ecs:cn-qingdao:*:instance/*"}],"Version": "1"}
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<?xml version="1.0" encoding="UTF-8" ?>
<CreatePolicyResponse>
	<Policy>
		<PolicyType>Custom</PolicyType>
		<Description>Query ECS instances in a specific region</Description>
		<DefaultVersion>v1</DefaultVersion>
		<PolicyName>View-ECS-instances-in-a-specific-region</PolicyName>
		<CreateDate>2021-10-13T02:46:57Z</CreateDate>
	</Policy>
	<RequestId>BA34C54A-C2B1-5A65-B6B0-B5842C1DB4DA</RequestId>
</CreatePolicyResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "Policy" : {
    "PolicyType" : "Custom",
    "Description" : "Query ECS instances in a specific region",
    "DefaultVersion" : "v1",
    "PolicyName" : "View-ECS-instances-in-a-specific-region",
    "CreateDate" : "2021-10-13T02:46:57Z"
  },
  "RequestId" : "BA34C54A-C2B1-5A65-B6B0-B5842C1DB4DA"
}

Error codes

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