# PolicyViolation

Violation produced by the validation plugin.

- Source: [`core/lib/validation/report.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/core/lib/validation/report.ts#L4)
- Type last changed: v2.251.0 · 24 Apr 2026

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
const policyViolation: cdk.PolicyViolation = {
  description: 'description',
  ruleName: 'ruleName',
  violatingResources: [{
    locations: ['locations'],

    // the properties below are optional
    constructPath: 'constructPath',
    resourceLogicalId: 'resourceLogicalId',
    templatePath: 'templatePath',
  }],

  // the properties below are optional
  fix: 'fix',
  ruleMetadata: {
    ruleMetadataKey: 'ruleMetadata',
  },
  severity: 'severity',
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk

policy_violation = cdk.PolicyViolation(
    description="description",
    rule_name="ruleName",
    violating_resources=[cdk.PolicyViolatingResource(
        locations=["locations"],

        # the properties below are optional
        construct_path="constructPath",
        resource_logical_id="resourceLogicalId",
        template_path="templatePath"
    )],

    # the properties below are optional
    fix="fix",
    rule_metadata={
        "rule_metadata_key": "ruleMetadata"
    },
    severity="severity"
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;

PolicyViolation policyViolation = PolicyViolation.builder()
        .description("description")
        .ruleName("ruleName")
        .violatingResources(List.of(PolicyViolatingResource.builder()
                .locations(List.of("locations"))

                // the properties below are optional
                .constructPath("constructPath")
                .resourceLogicalId("resourceLogicalId")
                .templatePath("templatePath")
                .build()))

        // the properties below are optional
        .fix("fix")
        .ruleMetadata(Map.of(
                "ruleMetadataKey", "ruleMetadata"))
        .severity("severity")
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;

var policyViolation = new PolicyViolation {
    Description = "description",
    RuleName = "ruleName",
    ViolatingResources = new [] { new PolicyViolatingResource {
        Locations = new [] { "locations" },

        // the properties below are optional
        ConstructPath = "constructPath",
        ResourceLogicalId = "resourceLogicalId",
        TemplatePath = "templatePath"
    } },

    // the properties below are optional
    Fix = "fix",
    RuleMetadata = new Dictionary<string, string> {
        { "ruleMetadataKey", "ruleMetadata" }
    },
    Severity = "severity"
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"

policyViolation := &PolicyViolation{
	Description: jsii.String("description"),
	RuleName: jsii.String("ruleName"),
	ViolatingResources: []PolicyViolatingResource{
		&PolicyViolatingResource{
			Locations: []*string{
				jsii.String("locations"),
			},

			// the properties below are optional
			ConstructPath: jsii.String("constructPath"),
			ResourceLogicalId: jsii.String("resourceLogicalId"),
			TemplatePath: jsii.String("templatePath"),
		},
	},

	// the properties below are optional
	Fix: jsii.String("fix"),
	RuleMetadata: map[string]*string{
		"ruleMetadataKey": jsii.String("ruleMetadata"),
	},
	Severity: jsii.String("severity"),
}
```

## Properties

- `description`: string (required) — The description of the violation.

- `fix`: string — How to fix the violation.

  **Default:** no fix is provided

- `ruleMetadata`: { [key: string]: string } — Additional metadata to include with the rule results.

  **Default:** no rule metadata

  This can be used to provide additional information that is
  plugin specific. The data provided here will be rendered as is.

- `ruleName`: string (required) — The name of the rule.

- `severity`: string — The severity of the violation, only used for reporting purposes.

  **Default:** no severity

  This is useful for helping the user discriminate between warnings,
  errors, information, etc.

- `violatingResources`: [PolicyViolatingResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.PolicyViolatingResource.html)[] (required) — The resources violating this rule.
