Creates a rule.
Limits
An ordinary account can contain up to 200 rules.
Usage notes
The sample request in this topic shows you how to create a rule based on the required-tags
managed rule. The return result shows that the rule is created and its ID is cr-5772ba41209e007b****
.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | CreateConfigRule |
The operation that you want to perform. Set the value to CreateConfigRule. |
ConfigRuleName | String | Yes | required-tags |
The name of the rule. |
Description | String | No | If the resource has all the specified tags, the configuration is considered compliant. You can define up to six groups of tags. |
The description of the rule. |
InputParameters | Map | No | null |
The input parameters of the rule. |
ConfigRuleTriggerTypes | String | Yes | ConfigurationItemChangeNotification |
The trigger type of the rule. Valid values:
|
MaximumExecutionFrequency | String | No | One_Hour |
The intervals at which the rule is triggered. Valid values:
Note This parameter is required if the ConfigRuleTriggerTypes parameter is set to ScheduledNotification.
|
ResourceTypesScope | Array of String | Yes | ACS::ECS::Instance |
The type of the resource to be evaluated by the rule. Separate multiple resource types with commas (,). |
RiskLevel | Integer | Yes | 1 |
The risk level of the resources that are not compliant with the rule. Valid values:
|
ClientToken | String | No | 1594295238-f9361358-5843-4294-8d30-b5183fac**** |
The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must make sure that it is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length. |
RegionIdsScope | String | No | cn-hangzhou |
The ID of the region to which the rule applies. Separate multiple region IDs with commas (,). Note This parameter applies only to a managed rule.
|
ExcludeResourceIdsScope | String | No | lb-t4nbowvtbkss7t326**** |
The ID of the resource to be excluded from the compliance evaluations performed by the rule. Separate multiple resource IDs with commas (,). Note This parameter applies only to a managed rule.
|
ResourceGroupIdsScope | String | No | rg-aekzc7r7rhx**** |
The ID of the resource group to which the rule applies. Separate multiple resource group IDs with commas (,). Note This parameter applies only to a managed rule.
|
TagKeyScope | String | No | ECS |
The tag key used to filter resources. The rule applies only to the resources with the specified tag key. Note This parameter applies only to a managed rule. You must set the
TagKeyScope and TagValueScope parameters at the same time.
|
TagValueScope | String | No | test |
The tag value used to filter resources. The rule applies only to the resources with the specified tag value. Note This parameter applies only to a managed rule. You must set the
TagKeyScope and TagValueScope parameters at the same time.
|
SourceOwner | String | Yes | ALIYUN |
The way in which the rule is to be created. Valid values:
|
SourceIdentifier | String | Yes | required-tags |
The identifier of the rule.
For more information about how to query the name of a managed rule, see Managed rules. |
TagKeyLogicScope | String | No | AND |
The logical relationship among the tag keys if you specify multiple tag keys by using
the
|
For more information about common request parameters, see Common parameters.
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
ConfigRuleId | String | cr-5772ba41209e007b**** |
The ID of the rule. |
RequestId | String | 6EC7AED1-172F-42AE-9C12-295BC2ADB751 |
The ID of the request. |
Examples
Sample requests
http(s)://[Endpoint]/?Action=CreateConfigRule
&ConfigRuleName=required-tags
&ConfigRuleTriggerTypes=ConfigurationItemChangeNotification
&ResourceTypesScope=["ACS::ECS::Instance"]
&RiskLevel=1
&SourceOwner=ALIYUN
&SourceIdentifier=required-tags
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<CreateConfigRuleResponse>
<ConfigRuleId>cr-5772ba41209e007b****</ConfigRuleId>
<RequestId>6EC7AED1-172F-42AE-9C12-295BC2ADB751</RequestId>
</CreateConfigRuleResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"ConfigRuleId" : "cr-5772ba41209e007b****",
"RequestId" : "6EC7AED1-172F-42AE-9C12-295BC2ADB751"
}
Error codes
HTTP status code | Error code | Error message | Description |
---|---|---|---|
400 | ExceedMaxRuleCount | The maximum number of rules is exceeded. | The error message returned because the number of existing rules reaches the upper limit. |
400 | ConfigRuleNotExists | The ConfigRule does not exist. | The error message returned because the specified rule does not exist. |
400 | ConfigRuleExists | The ConfigRule already exists. | The error message returned because the specified rule name already exists. |
404 | AccountNotExisted | Your account does not exist. | The error message returned because the specified account does not exist. |
503 | ServiceUnavailable | The request has failed due to a temporary failure of the server. | The error message returned because the service is unavailable. |
For a list of error codes, visit the API Error Center.