Updated on 2026-07-24 GMT+08:00

Adding a Custom Rule

Scenario

You can create custom rules with FunctionGraph if built-in policies cannot meet your resource audit requirements.

A custom policy is a function developed and published through FunctionGraph. Each custom rule is associated with a Function Graph function. Config reports events to the function. The function collects rule parameters and resource attributes from the events; evaluates whether your resources comply with the rule; and returns evaluation results using Open APIs of Config. Config sends events based on the trigger type (configuration changes or periodic) of a rule.

This section describes how to create a custom rule by performing the following two procedures:

  1. Creating a Function with FunctionGraph
  2. Adding a Custom Rule

Constraints and Limitations

  • You can add up to 500 rules in an account.
  • The resource recorder must be enabled for adding, modifying, enabling, or triggering a rule. If the resource recorder is disabled, you can only view, disable, and delete rules.

Only resources captured by the resource recorder are eligible for compliance rule evaluation. To ensure consistent and accurate evaluation results, maintain the resource recorder in an enabled state. The following scenarios describe the impact of recorder status on compliance:

  • Recorder disabled: Compliance rules cannot evaluate resource data while the recorder is inactive. However, previously generated evaluation results remain available.
  • Partial scope: If the monitoring scope is restricted to a subset of resources, compliance rules will only evaluate the selected resources.

For details about how to enable and configure the resource recorder, see Configuring the Resource Recorder.

Creating a Function with FunctionGraph

  1. Log in to the FunctionGraph console.
  2. In the navigation pane on the left, choose Functions > Function List.
  3. In the upper right corner, click Create Function. The Create from scratch tab is displayed by default.
  4. Set Function Type to Event Function and configure other parameters, including the function name and IAM agency.

    The agency grants the function required permissions and must include the rms:policyStates:update permission.

  5. Click Create Function.
  6. In the code box, enter a function and click Deploy.

    For details about example code, see Example Functions (Python).

  7. Click Configurations, modify Execution Timeout (s) and Memory (MB) in the Basic Settings area as required. Configure Concurrency.
  8. Click Save.

    For more details, see Creating an Event Function.

Adding a Custom Rule

  1. Log in to the Config console.
  2. In the navigation pane on the left, choose Resource Conformance.
  3. Click Add Rule in the middle of the page.
  4. Set Policy Type to Custom policy, complete related configurations and authorization, and click Next.

    Table 1 Parameters of basic configurations

    Parameter

    Description

    Policy Type

    Select Custom policy.

    You can use custom policies to create rules.

    Rule Name

    The name of the rule. A rule name must be unique.

    A rule name can contain digits, letters, underscores (_), and hyphens (-) and cannot exceed 64 characters.

    Description

    A rule description can contain any types of characters and cannot exceed 512 characters.

    URN of the FunctionGraph Function

    The URN of the function.

    For details about how to create a FunctionGraph function, see Creating a Function with FunctionGraph.

    NOTE:

    You can use either of the following methods to obtain the URN of a function:

    • On the FunctionGraph console, choose Functions > Function List in the navigation pane on the left and click Copy URN in the Operation column for the target function.
    • Return to the FunctionGraph console, choose Functions > Function List in the navigation pane on the left, click the name of the target function, then obtain the function URN in the Function Info area.

    Authorization

    This agency grants Config the read-only and call permissions of FunctionGraph. These permissions allow you to customize rules to query and send events to FunctionGraph functions.

    NOTE:
    • Auto create: Quickly create an agency named rms_custom_policy_agency. The permissions ensure proper functioning of a custom rule and allow a custom rule to obtain and asynchronously execute a FunctionGraph function.
    • Custom agency: Allows you to create an agency using Identity and Access Management (IAM) and assign permissions. The agency must contain the permissions for calling and asynchronously executing FunctionGraph functions. The authorization object must be Config. The following shows an authorization example:
        {
            "Version": "1.1",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Action": [
                        "functiongraph:function:invokeAsync",
                        "functiongraph:function:getConfig"
                    ]
                }
            ]
        } 

      For details about how to create an agency, see the Identity and Access Management User Guide.

    Figure 1 Basic Configurations

  5. On the displayed Configure Rule Parameters page, configure required parameters and click Next.

    Figure 2 Configuring rule parameters

    Table 2 Rule parameters

    Parameter

    Description

    Trigger Type

    The condition under which a rule will be triggered.

    Trigger types are as follows:

    • Configuration change: allows Config to trigger an evaluation for the rule upon resource configuration changes.
    • Periodic execution: triggers an evaluation for the rule at a specific frequency.

    Filter Type

    The type of resources to be evaluated.

    Filter types are as follows:

    • Specific resources: resources of a specific type
    • All resources: all resources of your account

    This parameter is mandatory only when Trigger Type is set to Configuration change.

    Resource Scope

    If you set Filter Type to Specific resources, you need to specify a resource scope.

    • Service: the service to which the resource belongs
    • Resource type: the resource type
    • Region: the region where the resource is deployed

    This parameter is mandatory only when Trigger Type is set to Configuration change and the Filter Type is set to Specific resources.

    (Optional) Filter Scope

    Specific resources whose configurations will be evaluated.

    You can enable this option and search for or filter out resources by resource ID or tag.

    This parameter is optional for a rule whose trigger type is Configuration change.

    Execute Every

    How often a rule will be triggered.

    Available options: 1 hour, 3 hours, 6 hours, 12 hours, 24 hours.

    This parameter is mandatory only when Trigger Type is set to Periodic execution.

    Configure Rule Parameters

    You can set up to 10 rule parameters for a custom rule.

    Tag

    Tag of the rule. To add a tag, click Add Tag and enter a tag key and a tag value. You can add up to 20 tags to a rule.

    • A tag key cannot be empty. It can contain letters, digits, spaces, and special characters (_.:+-@), but cannot start or end with a space or start with _sys_. It can contain a maximum of 128 characters.
    • A tag value cannot be empty. It can contain letters, digits, spaces, and special characters (_.:+-@), but cannot start or end with a space. A tag value can contain up to 255 characters.

  6. On the Confirm page, confirm the rule information and click Submit.

    After you add a rule, the first evaluation is automatically triggered immediately.

Verification

Go back to the Rules tab of the Resource Conformance page. If the new rule is displayed in the rule list and its policy type is Custom policy, the rule was successfully added.