Skill 5.1.1

Implement infrastructure as code by using declarative and imperative approaches (for example, AWS CloudFormation, AWS CDK).

Key Concepts

AWS CloudFormation is declarative: a JSON or YAML template describes resources, and CloudFormation works out the order of creation, updates and deletion. Change sets preview changes before execution, stack policies and deletion policies protect critical resources, drift detection finds manual changes, nested stacks and modules reuse components, and rollback triggers on CloudWatch alarms reverse failed updates. IaC generator can create templates from existing resources.

The AWS CDK lets engineers define infrastructure in TypeScript, Python, Java, C# or Go, using loops, conditions and classes. Constructs range from L1 (one CloudFormation resource) through L2 (resources with sensible defaults and helper methods, such as bucket.grantRead(role)) to L3 patterns that create whole architectures. cdk synth produces CloudFormation templates, so deployment still benefits from CloudFormation's change sets and rollback, and unit tests can assert what the synthesised template contains.