The CDK Construct Library for AWS::Config
Project description
AWS Config Construct Library
This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.
This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.
This module is part of the AWS Cloud Development Kit project.
Supported:
- Config rules
Not supported
- Configuration recoder
- Delivery channel
- Aggregation
Rules
AWS managed rules
To set up a managed rule, define a ManagedRule
and specify its identifier:
new ManagedRule(this, 'AccessKeysRotated', {
identifier: 'ACCESS_KEYS_ROTATED'
});
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:
new CustomRule(this, 'CustomRule', {
lambdaFunction: myFn,
configurationChanges: true,
periodic: true
});
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:
const sshRule = new ManagedRule(this, 'SSH', {
identifier: 'INCOMING_SSH_DISABLED'
});
// Restrict to a specific security group
rule.scopeToResource('AWS::EC2::SecurityGroup', 'sg-1234567890abcdefgh');
const customRule = new CustomRule(this, 'CustomRule', {
lambdaFunction: myFn,
configurationChanges: true
});
// Restrict to a specific tag
customRule.scopeToTag('Cost Center', 'MyApp');
Only one type of scope restriction can be added to a rule (the last call to scopeToXxx()
sets the scope).
Events
To define Amazon CloudWatch event rules, use the onComplianceChange()
or onReEvaluationStatus()
methods:
const rule = new CloudFormationStackDriftDetectionCheck(this, 'Drift');
rule.onComplianceChange('TopicEvent', {
target: new targets.SnsTopic(topic))
});
Example
Creating custom and managed rules with scope restriction and events:
// A custom rule that runs on configuration changes of EC2 instances
const fn = new lambda.Function(this, 'CustomFunction', {
code: lambda.AssetCode.inline('exports.handler = (event) => console.log(event);'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_8_10
});
const customRule = new config.CustomRule(this, 'Custom', {
configurationChanges: true,
lambdaFunction: fn
});
customRule.scopeToResource('AWS::EC2::Instance');
// A rule to detect stacks drifts
const driftRule = new config.CloudFormationStackDriftDetectionCheck(this, 'Drift');
// Topic for compliance events
const complianceTopic = new sns.Topic(this, 'ComplianceTopic');
// Send notification on compliance change
driftRule.onComplianceChange('ComplianceChange', {
target: new targets.SnsTopic(complianceTopic)
});
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aws-cdk.aws-config-0.36.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 216a5f7b7f5c3b049a41a848eb00002361d819ddbd9adf6f4105c5d7f783789e |
|
MD5 | 5dfc1830c166e6831b2d3dc4f44398c8 |
|
BLAKE2b-256 | dfbbd195bb50c716570f5b8b81a250b21c2d773da48a3a0bed050753b36c9c30 |
Hashes for aws_cdk.aws_config-0.36.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7765b01f45a940e34b2a7e224651936b40eb091998f12cbe91e843fad2d18c6f |
|
MD5 | 012eba8eb0cc685ecaf1b31436bdfefa |
|
BLAKE2b-256 | d627a64db7e3a4d7e498611b4ff54e966b279bb11cd118edad76e620442278da |