Skill 5.1.2

Design policy as code to perform proactive validation, enforcement, and drift remediation (for example, by using AWS CloudFormation Hooks, AWS CDK aspects, AWS Config rules, SCPs).

Key Concepts

Proactive validation: CDK aspects visit every construct during synthesis and can report or fix violations, such as a bucket without encryption; template scanners such as cfn-guard and cfn-lint run in pipelines. CloudFormation Hooks evaluate resources, stacks or change sets at provisioning time with Guard rules, Lambda functions or Control Tower proactive controls, and fail or warn before a non-compliant resource is created, regardless of which pipeline submitted the template.

Enforcement and drift remediation: SCPs deny non-compliant API calls from any tool, including the console, and AWS Config rules detect resources that drift out of compliance after deployment and trigger remediation through Systems Manager Automation. CloudFormation drift detection and periodic redeployment restore the declared state. Using several layers avoids gaps: hooks do not see console changes, and Config only detects problems after they exist.