Creates a rule based on a template or creates a custom rule based on Function Compute to check the compliance of resources. After a rule is created, it automatically performs an evaluation. Cloud Config then automatically triggers evaluations based on the trigger mechanism of the rule. You can also manually trigger evaluations.
Operation description
Limits
You can create up to 200 rules for each account.
Background information
Cloud Config supports the following methods to create rules:
-
Create a rule based on a template
A rule template is a rule function that Cloud Config has built in Function Compute. You can use a rule template to quickly create a rule. For more information about rules, see Definition and running principle of rules.
-
Create a rule based on Function Compute
A custom function rule is a custom rule whose code is hosted in a function of Function Compute. If the preset rule templates of Cloud Config cannot meet your compliance requirements, you can write function code to perform compliance checks in complex scenarios. For more information about custom function rules, see Definition and running principle of custom function rules.
Operation description
This topic provides an example of how to create a rule by using the rule template "required-tags". The response shows that the rule is created, and the rule ID is cr-5772ba41209e007b****.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
config:CreateConfigRule |
create |
*Rule
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
TagKeyScope
deprecated
|
string |
No |
[Deprecated] Use the The rule applies only to resources that have the specified tag keys. Note
This parameter applies only to managed rules. You must set both |
ECS |
TagValueScope
deprecated
|
string |
No |
[Deprecated] Use the The rule applies only to resources that have the specified tag values. Note
This parameter applies only to rule templates. You must set both |
test |
| TagKeyLogicScope |
string |
No |
The logical relationship when the This parameter can also be used with the deprecated Valid values:
Valid values:
|
AND |
| TagsScope |
array<object> |
No |
The tag scope. |
|
|
object |
No |
|||
| TagKey |
string |
No |
The tag key. |
key-1 |
| TagValue |
string |
No |
The tag value. |
value-1 |
| ExcludeTagsScope |
array<object> |
No |
The excluded tag scope. |
|
|
object |
No |
|||
| TagKey |
string |
No |
The tag key. |
key-2 |
| TagValue |
string |
No |
The tag value. |
value-2 |
| Description |
string |
No |
The description of the rule. |
You can define up to 6 tag groups. If a resource has all specified tags, the resource is considered "compliant" |
| SourceOwner |
string |
Yes |
The type of the rule to create. Valid values:
Valid values:
|
ALIYUN |
| MaximumExecutionFrequency |
string |
No |
The execution frequency of the rule. Valid values:
Note
This parameter is required when ConfigRuleTriggerTypes is set to ScheduledNotification. Valid values:
|
One_Hour |
| Conditions |
string |
No |
The conditions of the custom condition rule, in JSON format. |
{"ComplianceConditions":"{\"operator\":\"and\",\"children\":[{\"operator\":\"StringEquals\",\"featurePath\":\"$.Status\",\"desired\":\"1\",\"featureSource\":\"CONFIGURATION\"}]}"} |
| RegionIdsScope |
string |
No |
The rule applies only to resources in the specified region IDs. Separate multiple region IDs with commas (,). Note
This parameter applies only to rule templates. |
cn-hangzhou |
| ExcludeRegionIdsScope |
string |
No |
The rule does not apply to resources in the specified regions. Resources in those regions are not evaluated. Separate multiple region IDs with commas (,). |
cn-shanghai |
| ResourceGroupIdsScope |
string |
No |
The rule applies only to resources in the specified resource group IDs. Separate multiple resource group IDs with commas (,). Note
This parameter applies only to rule templates. |
rg-aekzc7r7rhx**** |
| ExcludeResourceGroupIdsScope |
string |
No |
The rule does not apply to resources in the specified resource group IDs. Resources in those resource groups are not evaluated. Separate multiple resource group IDs with commas (,). |
rg-bnczc6r7rml**** |
| InputParameters |
object |
No |
The input parameters of the rule. You can obtain the input parameters by calling the GetManagedRule operation. Check the The input parameters are in the format of |
{"key1":"value1","key2":"value2"} |
| ResourceIdsScope |
string |
No |
The rule applies only to the specified resource IDs. Separate multiple resource IDs with commas (,). |
lb-5cmbowstbkss9ta03**** |
| ExcludeResourceIdsScope |
string |
No |
The rule does not apply to the specified resource IDs. The specified resources are not evaluated. Separate multiple resource IDs with commas (,). Note
This parameter applies only to rule templates. |
lb-t4nbowvtbkss7t326**** |
| SourceIdentifier |
string |
Yes |
The identity of the rule template.
|
required-tags |
| ConfigRuleTriggerTypes |
string |
Yes |
The trigger mechanism of the rule. Valid values:
Note
If the rule includes both trigger mechanisms, separate them with a comma (,). |
ConfigurationItemChangeNotification |
| ConfigRuleName |
string |
Yes |
The name of the rule. |
required-tags |
| ClientToken |
string |
No |
The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but you must make sure that the token is unique among different requests. The |
1594295238-f9361358-5843-4294-8d30-b5183fac**** |
| ResourceTypesScope |
array |
Yes |
The resource types to be evaluated by the rule. The actual parameter format is a comma-separated string (for example, ACS::ECS::Instance,ACS::RDS::DBInstance). JSON arrays or indexed parameters in the format of ResourceTypesScope.1 are not supported. |
ACS::ECS::Instance |
|
string |
No |
The resource types to be evaluated by the rule. Separate multiple resource types with commas (,). |
ACS::ECS::Instance |
|
| RiskLevel |
integer |
Yes |
The risk level of the rule. Valid values:
Valid values:
|
1 |
| ExtendContent |
string |
No |
The extended content. Currently, this parameter is used only to set the trigger time for the 24-hour periodic trigger. |
{"fixedHour":"13"} |
| Tag |
array<object> |
No |
The tags of the created rule. |
|
|
object |
No |
The tags of the resource. You can add up to 20 tags. |
||
| Key |
string |
No |
The tag key of the resource. You can specify up to 20 tag keys. |
key-1 |
| Value |
string |
No |
The tag value of the resource. You can specify up to 20 tag values. |
value-1 |
| ResourceNameScope |
string |
No |
The rule applies only to resources with the specified resource name. |
i-xxx |
For more information about common request parameters, see Common parameters.
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The response parameters. |
||
| ConfigRuleId |
string |
The rule ID. |
cr-5772ba41209e007b**** |
| RequestId |
string |
The request ID. |
6EC7AED1-172F-42AE-9C12-295BC2ADB751 |
Examples
Success response
JSON format
{
"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. | |
| 400 | ConfigRuleNotExists | The ConfigRule does not exist. | The rule does not exist. |
| 400 | ConfigRuleExists | The ConfigRule already exists. | |
| 404 | AccountNotExisted | Your account does not exist. | |
| 503 | ServiceUnavailable | The request has failed due to a temporary failure of the server. | The request has failed due to a temporary failure of the server. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.