AWS Config Construct Library

--- ![cfn-resources: Stable]( > All classes with the `Cfn` prefix in this module ([CFN Resources]( are always stable and safe to use. ![cdk-constructs: Developer Preview]( > The APIs of higher level constructs in this module are in **developer preview** before they become stable. We will only make breaking changes to address unforeseen API issues. Therefore, these APIs are not subject to [Semantic Versioning](, and breaking changes will be announced in release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. ---

This module is part of the AWS Cloud Development Kit project.


  • Config rules

Not supported

  • Configuration recoder

  • Delivery channel

  • Aggregation

Initial Setup

Before using the constructs provided in this module, you need to setup AWS Config in the region you plan on using it in. This setup includes:

  • ConfigurationRecorder: Configure which resources will be recorded for config changes.

  • DeliveryChannel: Configure where to store the recorded data.

Following are the guides to setup AWS Config:


AWS managed rules

To set up a managed rule, define a ManagedRule and specify its identifier:

# Example automatically generated without compilation. See
ManagedRule(self, "AccessKeysRotated",

Available identifiers and parameters are listed in the List of AWS Config Managed Rules.

Higher level constructs for managed rules are available, see Managed Rules. Prefer to use those constructs when available (PRs welcome to add more of those).

Custom rules

To set up a custom rule, define a CustomRule and specify the Lambda Function to run and the trigger types:

# Example automatically generated without compilation. See
CustomRule(self, "CustomRule",

Restricting the scope

By default rules are triggered by changes to all resources. Use the scopeToResource(), scopeToResources() or scopeToTag() methods to restrict the scope of both managed and custom rules:

# Example automatically generated without compilation. See
ssh_rule = ManagedRule(self, "SSH",

# Restrict to a specific security group
rule.scope_to_resource("AWS::EC2::SecurityGroup", "sg-1234567890abcdefgh")

custom_rule = CustomRule(self, "CustomRule",

# Restrict to a specific tag
custom_rule.scope_to_tag("Cost Center", "MyApp")

Only one type of scope restriction can be added to a rule (the last call to scopeToXxx() sets the scope).


To define Amazon CloudWatch event rules, use the onComplianceChange() or onReEvaluationStatus() methods:

# Example automatically generated without compilation. See
rule = CloudFormationStackDriftDetectionCheck(self, "Drift")


Creating custom and managed rules with scope restriction and events:

# Example automatically generated. See
# A custom rule that runs on configuration changes of EC2 instances
fn = lambda.Function(self, "CustomFunction",
    code=lambda.AssetCode.from_inline("exports.handler = (event) => console.log(event);"),

custom_rule = config.CustomRule(self, "Custom",


# A rule to detect stacks drifts
drift_rule = config.CloudFormationStackDriftDetectionCheck(self, "Drift")

# Topic for compliance events
compliance_topic = sns.Topic(self, "ComplianceTopic")

# Send notification on compliance change