RuleScope Class
Determines which resources trigger an evaluation of an AWS Config rule.
| Source | aws-config/lib/rule.ts |
|---|
Example
ts
// Lambda function containing logic that evaluates compliance with the rule.
const evalComplianceFn = new lambda.Function(this, "CustomFunction", {
code: lambda.AssetCode.fromInline(
"exports.handler = (event) => console.log(event);"
),
handler: "index.handler",
runtime: lambda.Runtime.NODEJS_LATEST,
});
// A custom rule that runs on configuration changes of EC2 instances
const customRule = new config.CustomRule(this, "Custom", {
configurationChanges: true,
lambdaFunction: evalComplianceFn,
ruleScope: config.RuleScope.fromResource(config.ResourceType.EC2_INSTANCE),
});
python
# Lambda function containing logic that evaluates compliance with the rule.
eval_compliance_fn = lambda_.Function(self, "CustomFunction",
code=lambda_.AssetCode.from_inline("exports.handler = (event) => console.log(event);"),
handler="index.handler",
runtime=lambda_.Runtime.NODEJS_LATEST
)
# A custom rule that runs on configuration changes of EC2 instances
custom_rule = config.CustomRule(self, "Custom",
configuration_changes=True,
lambda_function=eval_compliance_fn,
rule_scope=config.RuleScope.from_resource(config.ResourceType.EC2_INSTANCE)
)
java
// Lambda function containing logic that evaluates compliance with the rule.
Function evalComplianceFn = Function.Builder.create(this, "CustomFunction")
.code(AssetCode.fromInline("exports.handler = (event) => console.log(event);"))
.handler("index.handler")
.runtime(Runtime.NODEJS_LATEST)
.build();
// A custom rule that runs on configuration changes of EC2 instances
CustomRule customRule = CustomRule.Builder.create(this, "Custom")
.configurationChanges(true)
.lambdaFunction(evalComplianceFn)
.ruleScope(RuleScope.fromResource(ResourceType.EC2_INSTANCE))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Lambda function containing logic that evaluates compliance with the rule.
var evalComplianceFn = new Function(this, "CustomFunction", new FunctionProps {
Code = AssetCode.FromInline("exports.handler = (event) => console.log(event);"),
Handler = "index.handler",
Runtime = Runtime.NODEJS_LATEST
});
// A custom rule that runs on configuration changes of EC2 instances
var customRule = new CustomRule(this, "Custom", new CustomRuleProps {
ConfigurationChanges = true,
LambdaFunction = evalComplianceFn,
RuleScope = RuleScope.FromResource(ResourceType.EC2_INSTANCE)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Lambda function containing logic that evaluates compliance with the rule.
evalComplianceFn := lambda.NewFunction(this, jsii.String("CustomFunction"), &FunctionProps{
Code: lambda.AssetCode_FromInline(jsii.String("exports.handler = (event) => console.log(event);")),
Handler: jsii.String("index.handler"),
Runtime: lambda.Runtime_NODEJS_LATEST(),
})
// A custom rule that runs on configuration changes of EC2 instances
customRule := config.NewCustomRule(this, jsii.String("Custom"), &CustomRuleProps{
ConfigurationChanges: jsii.Boolean(true),
LambdaFunction: evalComplianceFn,
RuleScope: config.RuleScope_FromResource(config.ResourceType_EC2_INSTANCE()),
})
Properties
keymay be undefinedstringkeymay be undefinedstrkeymay be undefinedStringKeymay be undefinedstringKeymay be undefined*string #tag key applied to resources that will trigger evaluation of a rule.
resourceIdmay be undefinedstringresource_idmay be undefinedstrresourceIdmay be undefinedStringResourceIdmay be undefinedstringResourceIdmay be undefined*string #ID of the only AWS resource that will trigger evaluation of a rule.
resourceTypesmay be undefinedResourceType[]resource_typesmay be undefinedtyping.List[ResourceType]resourceTypesmay be undefinedList<ResourceType>ResourceTypesmay be undefinedResourceType[]ResourceTypesmay be undefined*[]ResourceType #Resource types that will trigger evaluation of a rule.
valuemay be undefinedstringvaluemay be undefinedstrvaluemay be undefinedStringValuemay be undefinedstringValuemay be undefined*string #tag value applied to resources that will trigger evaluation of a rule.
Methods
fromResource(resourceType: ResourceType, resourceId?: string): RuleScope // chainable@staticmethod def from_resource(resource_type: ResourceType, resource_id: typing.Optional[str] = None) -> RuleScopepublic static RuleScope fromResource(ResourceType resourceType, String resourceId)public static RuleScope FromResource(ResourceType resourceType, string? resourceId = null)func FromResource(ResourceType ResourceType, ResourceId *string) RuleScope static #restricts scope of changes to a specific resource type or resource identifier.
fromResources(resourceTypes: ResourceType[]): RuleScope // chainable@staticmethod def from_resources(resource_types: typing.List[ResourceType]) -> RuleScopepublic static RuleScope fromResources(List<ResourceType> resourceTypes)public static RuleScope FromResources(ResourceType[] resourceTypes)func FromResources(ResourceTypes *[]ResourceType) RuleScope static #restricts scope of changes to specific resource types.
fromTag(key: string, value?: string): RuleScope // chainable@staticmethod def from_tag(key: str, value: typing.Optional[str] = None) -> RuleScopepublic static RuleScope fromTag(String key, String value)public static RuleScope FromTag(string key, string? value = null)func FromTag(Key *string, Value *string) RuleScope static #restricts scope of changes to a specific tag.