Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): cannot scope a custom rule without configurationChanges …
…on (#8738) While CloudFormation allows to specify the scope for a custom ConfigRule without necessarily specifying `configurationChanges: true`, this was not allowed by the corresponding construct. This removed the offending guard, and replaced the test that verified the throwing behavior with a regression test that validates this configuration is allowed. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
c1d4e0f
commit 841060d
Showing
4 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/@aws-cdk/aws-config/test/integ.scoped-rule.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
"Resources": { | ||
"CustomFunctionServiceRoleD3F73B79": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
}, | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSConfigRulesExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"CustomFunctionBADD59E7": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = (event) => console.log(event);" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"CustomFunctionServiceRoleD3F73B79", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs10.x" | ||
}, | ||
"DependsOn": [ | ||
"CustomFunctionServiceRoleD3F73B79" | ||
] | ||
}, | ||
"CustomFunctionPermission41887A5E": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Fn::GetAtt": [ | ||
"CustomFunctionBADD59E7", | ||
"Arn" | ||
] | ||
}, | ||
"Principal": "config.amazonaws.com" | ||
} | ||
}, | ||
"Custom8166710A": { | ||
"Type": "AWS::Config::ConfigRule", | ||
"Properties": { | ||
"Source": { | ||
"Owner": "CUSTOM_LAMBDA", | ||
"SourceDetails": [ | ||
{ | ||
"EventSource": "aws.config", | ||
"MessageType": "ScheduledNotification" | ||
} | ||
], | ||
"SourceIdentifier": { | ||
"Fn::GetAtt": [ | ||
"CustomFunctionBADD59E7", | ||
"Arn" | ||
] | ||
} | ||
}, | ||
"Scope": { | ||
"ComplianceResourceTypes": [ | ||
"AWS::EC2::Instance" | ||
] | ||
} | ||
}, | ||
"DependsOn": [ | ||
"CustomFunctionPermission41887A5E", | ||
"CustomFunctionBADD59E7", | ||
"CustomFunctionServiceRoleD3F73B79" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as lambda from '@aws-cdk/aws-lambda'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as config from '../lib'; | ||
|
||
const app = new cdk.App(); | ||
|
||
const stack = new cdk.Stack(app, 'aws-cdk-config-rule-scoped-integ'); | ||
|
||
const fn = new lambda.Function(stack, 'CustomFunction', { | ||
code: lambda.AssetCode.fromInline('exports.handler = (event) => console.log(event);'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
}); | ||
|
||
const customRule = new config.CustomRule(stack, 'Custom', { | ||
lambdaFunction: fn, | ||
periodic: true, | ||
}); | ||
|
||
customRule.scopeToResource('AWS::EC2::Instance'); | ||
|
||
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters