AWS Config Custom Rules
AWS Config Custom Rules are rules that you create from scratch. There are two ways to create
AWS Config custom rules: with Lambda functions (AWS Lambda Developer Guide) and with Guard (Guard GitHub
Repository
AWS Config custom rules created with Lambda are called AWS Config Custom Lambda Rules and AWS Config custom rules created with Guard are called AWS Config Custom Policy Rules.
AWS Config Custom Policy Rules
Rules written using Guard can be created from the AWS Config console or by using the
AWS Config rule APIs. AWS Config Custom Policy rules allow you to create AWS Config Custom rules without
needing to use Java or Python to develop Lambda functions to manage your custom rules.
AWS Config Custom Policy rules are initiated by configuration changes. For more information
about Guard, see the Guard GitHub
Repository
AWS Config Custom Lambda Rules
Custom Lambda rules provide you with the option to use Java or Python to create a Lambda function for a AWS Config Custom rule. A Lambda function is custom code that you upload to AWS Lambda, and it is invoked by events that are published to it by an event source. If the Lambda function is associated with an AWS Config rule, AWS Config invokes it when the rule is initiated. The Lambda function then evaluates the configuration information that is sent by AWS Config, and it returns the evaluation results. For more information about Lambda functions, see Function and Event Sources in the AWS Lambda Developer Guide.
Cost Considerations
For details about the costs associated with resource recording, see
AWS Config pricing
Recommendation: Add logic to handle the evaluation of deleted resources for custom lambda rules
When creating AWS Config custom lambda rules, it is highly recommended that you add logic to handle the evaluation of deleted resources.
When evaluation results are marked as NOT_APPLICABLE
, they will be marked for deletion and cleaned up.
If they're NOT marked as NOT_APPLICABLE
,
the evaluation results will remain unchanged until the rule is deleted, which can cause an unexpected spike in the creation of configuration items (CIs) for AWS::Config::ResourceCompliance
upon rule deletion.
For information on how to set AWS Config custom lambda rules to return NOT_APPLICABLE
for deleted resources,
see Managing deleted resources with AWS Config custom lambda rules.
Recommendation: Provide the resources in scope for custom lambda rules
AWS Config Custom Lambda Rules can cause a high number of Lambda function invocations if the rule is not scoped to one or more resource types. To avoid increased activity associated with your account, it is highly recommended to provide resources in scope for your Custom Lambda rules. If no resource types are selected, the rule will invoke the Lambda function for all resources in the account.
Recommendation: Stop recording resource compliance before deleting rules
It is highly recommended that you stop recording for the AWS::Config::ResourceCompliance
resource type before you delete rules in your account.
Deleting rules creates CIs for AWS::Config::ResourceCompliance
and can affect your AWS Config configuration recorder costs.
If you are deleting rules which evaluate a large number of resource types,
this can lead to a spike in the number of CIs recorded.
Best practice:
Stop recording
AWS::Config::ResourceCompliance
Delete rule(s)
Turn on recording for
AWS::Config::ResourceCompliance
Trigger Types
After you add a rule to your account, AWS Config compares your resources to the conditions of the rule. After this initial evaluation, AWS Config continues to run evaluations each time one is triggered. The evaluation triggers are defined as part of the rule, and they can include the following types.
Trigger type | Description |
---|---|
Configuration changes | AWS Config runs evaluations for the rule when there is a resource that matches
the rule's scope and there is a change in configuration of the resource. The
evaluation runs after AWS Config sends a configuration item change
notification.
You choose which resources initiate the evaluation by defining the rule's scope. The scope can include the following:
AWS Config runs the evaluation when it detects a change to a resource that matches the rule's scope. You can use the scope to define which resources initiate evaluations. |
Periodic | AWS Config runs evaluations for the rule at a frequency that you choose; for example, every 24 hours. |
Hybrid | Some rules have both configuration change and periodic triggers. For these rules, AWS Config evaluates your resources when it detects a configuration change and also at the frequency that you specify. |
Evaluation Modes
There are two evaluation modes for AWS Config rules.
Evaluation mode | Description |
---|---|
Proactive | Use proactive evaluation to evaluate resources before they have been deployed. This allows you to evaluate whether a set of resource properties, if used to define an AWS resource, would be COMPLIANT or NON_COMPLIANT given the set of proactive rules that you have in your account in your Region. For more information, see Evaluation modes. For a list of managed rules that support proactive evaluation, see List of AWS Config Managed Rules by Evaluation Mode. |
Detective | Use detective evaluation to evaluate resources that have already been deployed. This allows you to evaluate the configuration settings of your existing resources. |
Note
Proactive rules do not remediate resources that are flagged as NON_COMPLIANT or prevent them from being deployed.