Creates a rule.

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

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 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 6 groups of tags.

The description of the rule.

InputParameters Map No null

The settings of the input parameters for the rule.

ConfigRuleTriggerTypes String Yes ConfigurationItemChangeNotification

The trigger type of the rule. Valid values:

  • ConfigurationItemChangeNotification: The rule is triggered by configuration changes.
  • ScheduledNotification: The rule is triggered as scheduled.
MaximumExecutionFrequency String No One_Hour

The intervals at which the rule is triggered. Valid values:

  • One_Hour: 1 hour.
  • Three_Hours: 3 hours.
  • Six_Hours: 6 hours.
  • Twelve_Hours: 12 hours.
  • TwentyFour_Hours:24 hours. This is the default value.
Note If the ConfigRuleTriggerTypes parameter is set to ScheduledNotification, you must set this parameter.
ResourceTypesScope Array of String Yes ACS::ECS::Instance

The type of the resources to be evaluated. Separate multiple resource types with commas (,).

RiskLevel Integer Yes 1

The risk level of the resources that are not compliant with the rules. Valid values:

  • 1: high risk level.
  • 2: medium risk level.
  • 3: low risk level.
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 client token can contain only ASCII characters. It 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 rule that is to be created based on 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 rule that is to be created based on 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 rule that is to be created based on 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 rule that is to be created based on 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 rule that is to be created based on 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:

  • ALIYUN: The rule is to be created based on a managed rule of Alibaba Cloud.
  • CUSTOM_FC: The rule is a custom rule.
SourceIdentifier String Yes required-tags

The identifier of the rule.

  • If the SourceOwner parameter is set to ALIYUN, set the value to the name of the managed rule.
  • If the SourceOwner parameter is set to CUSTOM_FC, set the value to the Alibaba Cloud Resource Name (ARN) of the relevant function in Function Compute.

For more information about how to query the name of a managed rule, see Managed rules.

For 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 your 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.