All Products
Search
Document Center

Resource Access Management:CreatePolicy

更新時間:Aug 09, 2024

Creates a custom policy.

Operation description

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.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
ram:CreatePolicycreate
  • Policy
    acs:ram:*:{#accountId}:policy/{#PolicyName}
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
PolicyNamestringYes

The name of the policy.

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

View-ECS-instances-in-a-specific-region
DescriptionstringNo

The description of the policy.

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

Query ECS instances in a specific region
PolicyDocumentstringYes

The document of the policy.

The document must be 1 to 6,144 characters in length.

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

{"Statement": [{"Effect": "Allow","Action": "ecs:Describe*","Resource": "acs:ecs:cn-qingdao:*:instance/*"}],"Version": "1"}

Response parameters

ParameterTypeDescriptionExample
object
Policyobject

The information about the policy.

DefaultVersionstring

The version of the policy. Default value: v1.

v1
Descriptionstring

The description of the policy.

Query ECS instances in a specific region
PolicyNamestring

The name of the policy.

View-ECS-instances-in-a-specific-region
CreateDatestring

The time when the policy was created.

2021-10-13T02:46:57Z
PolicyTypestring

The type of the policy. Valid values:

  • Custom: custom policy
  • System: system policy
Custom
RequestIdstring

The ID of the request.

BA34C54A-C2B1-5A65-B6B0-B5842C1DB4DA

Examples

Sample success responses

JSONformat

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

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
No change history