All Products
Search
Document Center

API Gateway:CreateAndAttachPolicy

Last Updated:Dec 17, 2025

Creates and associates a policy.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

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:
    • For mandatory resource types, indicate with a prefix of * .
    • 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
apig:CreateAndAttachPolicynone
*Policy
acs:apig:{#regionId}:{#accountId}:policy/*
    none
none

Request syntax

POST /v1/policies HTTP/1.1

Request parameters

ParameterTypeRequiredDescriptionExample
bodyobjectNo

The request data.

namestringNo

The policy name.

test
classNamestringYes

The class name supported by the policy. Different policies support different resources. This parameter is used in combination with AttachResourceType.

  • RateLimit: throttles traffic. Supported: HttpApi, Operation, and GatewayRoute.
  • ConcurrencyLimit: controls concurrency. Supported: HttpApi, Operation, and GatewayRoute.
  • CircuitBreaker: breaks circuits and downgrades traffic. Supported: HttpApi, Operation, and GatewayRoute.
  • HttpRewrite: rewrites HTTP traffic. Supported: HttpApi, Operation, and GatewayRoute.
  • HeaderModify: modifies headers. Supported: HttpApi, Operation, and GatewayRoute.
  • Cors: supports CORS. Supported: HttpApi, Operation, and GatewayRoute.
  • FlowCopy: replicates traffic. Supported: HttpApi, Operation, and GatewayRoute.
  • Timeout: times out requests. Supported: HttpApi, Operation, and GatewayRoute.
  • Retry: retries requests. Supported: HttpApi, Operation, and GatewayRoute.
  • IpAccessControl: implements IP address-based access control. Supported: HttpApi, Operation, GatewayRoute, Domain, and Gateway.
  • DirectResponse: mocks responses. Supported: Operation and GatewayRoute.
  • Redirect: redirects traffic. Supported: GatewayRoute.
  • Fallback: implements fallback. Supported: Operation and GatewayRoute.
  • ServiceTls: implements TLS authentication. Supported: GatewayService.
  • ServiceLb: balances loads. Supported: GatewayService.
  • ServicePortTls: implements service port TLS authentication. Supported: GatewayServicePort.
  • Waf: implements WAF protection. Supported: GatewayRoute and Gateway.
  • JWTAuth: implements global JWT authentication. Supported: Gateway.
  • OIDCAuth: implements global OIDC authentication. Supported: Gateway.
  • ExternalZAuth: implements custom authentication. Supported: Gateway.
IpAccessControl
configstringYes

The policy configurations.

{\"enable\":false}
descriptionstringNo

The policy description.

This is the policy description.
attachResourceIdsarrayYes

The IDs of the resources to be associated with the policy.

stringNo

The resource ID.

api-cq7l5s5lhtgi6qasrdc0
attachResourceTypestringYes

The supported resource type. Valid values:

  • HttpApi: an HTTP API
  • Operation: an operation in an HTTP API
  • GatewayRoute: a route
  • GatewayService: a service
  • GatewayServicePort: a service port
  • Domain: a domain name
  • Gateway: an instance
HttpApi
environmentIdstringNo

The environment ID.

env-cq7l5s5lhtgi6qasrdc0
gatewayIdstringNo

The instance ID.

gw-cq7l5s5lhtgi6qasrdc0

Response parameters

ParameterTypeDescriptionExample
object

Schema of Response

requestIdstring

The request ID, which is used to trace the call link.

585657D2-1C20-5B8A-AF17-D727C6490BE4
codestring

The status code returned.

Ok
messagestring

The response message returned.

success
dataobject

The returned data.

policyIdstring

The policy ID.

p-cq7l5s5lhtgi6qasrdc0
attachmentAttachment

The association information of the policy.

Examples

Sample success responses

JSONformat

{
  "requestId": "585657D2-1C20-5B8A-AF17-D727C6490BE4",
  "code": "Ok",
  "message": "success",
  "data": {
    "policyId": "p-cq7l5s5lhtgi6qasrdc0\n",
    "attachment": {
      "policyAttachmentId": "pr-cq7l5s5lhtgi6qasrdc0",
      "attachResourceIds": [
        "api-cq7l5s5lhtgi6qasrdc0"
      ],
      "attachResourceType": "HttpApi",
      "environmentId": "env-cq7l5s5lhtgi6qasrdc0",
      "gatewayId": "gw-cpr4f9dlhtgq5ksfgmb0"
    }
  }
}

Error codes

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