# RuleScope

Determines which resources trigger an evaluation of an AWS Config rule.

Obtainable from: RuleScope.fromResource, RuleScope.fromResources, RuleScope.fromTag

- Source: [`aws-config/lib/rule.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-config/lib/rule.ts#L172)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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)
});
```

Golang:

```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

- `key`: string — tag key applied to resources that will trigger evaluation of a rule.

- `resourceId`: string — ID of the only AWS resource that will trigger evaluation of a rule.

- `resourceTypes`: [ResourceType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_config.ResourceType.html)[] — Resource types that will trigger evaluation of a rule.

- `value`: string — tag value applied to resources that will trigger evaluation of a rule.

## Methods

- `fromResource(resourceType: ResourceType, resourceId?: string): RuleScope // chainable` (static) — restricts scope of changes to a specific resource type or resource identifier.

- `fromResources(resourceTypes: ResourceType[]): RuleScope // chainable` (static) — restricts scope of changes to specific resource types.

- `fromTag(key: string, value?: string): RuleScope // chainable` (static) — restricts scope of changes to a specific tag.
