Support setting up ConfigurationRecorder and DeliveryChannel in AWS Config
See original GitHub issueI’m using CDK v0.36, but the current version (v1.2) doesn’t appear to different substantively.
Currently, the CDK does not provide a convenient Construct to get a working AWS Config ConfigurationRecorder up and running. This forces users to create a number of resources manually, even though every customer will define the same resources. Given one cannot use AWS Config without a ConfigurationRecorder, this seems like opportunity to add a new construct to do this for our customers.
Additionally, there are no L2 constructs for some resources.
Consider the following example code. The IAM permissions that AWS Config must have in order to function correctly are documented more here, and the bucket configuration is documented here.
import config = require('@aws-cdk/aws-config');
import iam = require('@aws-cdk/aws-iam');
import s3 = require('@aws-cdk/aws-s3');
const awsConfigBucket = new s3.Bucket(this, 'BucketAwsConfig', {versioned: true});
const policyStatement1 = new iam.PolicyStatement({
actions: ['s3:*'],
principals: [new iam.AnyPrincipal()],
resources: [`${awsConfigBucket.bucketArn}/*`],
conditions: {'Bool': {'aws:SecureTransport': false}}
});
policyStatement1.effect = iam.Effect.DENY;
awsConfigBucket.addToResourcePolicy(policyStatement1);
const policyStatement2 = new iam.PolicyStatement({
actions: ['s3:PutObject'],
principals: [new iam.ServicePrincipal('config.amazonaws.com')],
resources: [`${awsConfigBucket.bucketArn}/*`],
conditions: {'StringEquals': { "s3:x-amz-acl": "bucket-owner-full-control" }}
});
policyStatement2.effect = iam.Effect.ALLOW;
awsConfigBucket.addToResourcePolicy(policyStatement2);
const policyStatement3 = new iam.PolicyStatement({
actions: ['s3:GetBucketAcl'],
principals: [new iam.ServicePrincipal('config.amazonaws.com')],
resources: [awsConfigBucket.bucketArn]
});
policyStatement3.effect = iam.Effect.ALLOW;
awsConfigBucket.addToResourcePolicy(policyStatement3);
const awsConfigRole = new iam.Role(this, 'RoleAwsConfig', {
assumedBy: new iam.ServicePrincipal('config.amazonaws.com')
});
awsConfigRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSConfigRole'))
new config.CfnDeliveryChannel(this, "DeliveryChannel", {s3BucketName: awsConfigBucket.bucketName});
new config.CfnConfigurationRecorder(this, "Recorder", {
name: "default",
roleArn: awsConfigRole.roleArn
});
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Managing the Delivery Channel - AWS Config
As AWS Config continually records the changes that occur to your AWS resources, it sends notifications and updated configuration states through the delivery...
Read more >How can I recreate an AWS Config delivery channel?
1. Open the IAM console. 2. Choose Roles, and then choose Create role. 3. In Select type of trusted entity, choose AWS service...
Read more >AWS::Config::DeliveryChannel - AWS CloudFormation
Specifies a delivery channel object to deliver configuration information to an Amazon S3 bucket and Amazon SNS topic. Before you can create a...
Read more >Managing the Configuration Recorder - AWS Config
AWS Config uses the configuration recorder to detect changes in your resource configurations and capture these changes as configuration items.
Read more >DeliveryChannel - AWS Config
By default, AWS Config assigns the name "default" when creating the delivery channel. To change the delivery channel name, you must use the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm the following works (assume we’ve created the needed role and a bucket outside of this stack):
Adding a
add_depends_on
for the config_recorder to depend on the delivery_channel stalls the CloudFormation deployment. Without it it deployed fine.For what it is worth, I found that you can use the following CfnResource constructs to workaround this edge. Note that you would likely need to check if a Service Role already exists for Config in the target region, because those operations are not idempotent. I believe the same goes for the Delivery Channel and Recorder resources.
Also, there is not currently a clean way to return an Arn value for the
CfnServiceLinkedRole
construct when using.getAtt()
. It will not returnArn
orroleArn
in the ref, so for our purposes we hardcoded the Arn string. This is admittedly a bit ugly, but it does function correctly when deploying the CFT.When deployed, the Configuration Recorder resource will wait for the Delivery Channel resource to become available before finalizing creation. Be warned: if you have any errors in your Delivery Channel configuration, it may take the full timeout duration for the operation to fail (1hr default).