Volume 9 · Chapter 9 — CI/CD, DevOps and Infrastructure as Code

CDK, SAM, and Higher-Level IaC

Goutham Mayaluri 4 min read AWSCloudCI/CDInfrastructure as Code

9.1 Introduction

CloudFormation is the foundation, but the exam expects awareness of the higher-level IaC options - the Cloud Development Kit (CDK), the Serverless Application Model (SAM), and how they relate to CloudFormation and Terraform. This chapter clarifies when to reach for each.

9.2 The Cloud Development Kit (CDK)

TheAWS CDKlets you define infrastructure in real programming languages (TypeScript, Python, Java, C#) usingconstructs- reusable, higher-level components that encapsulate best practices (an L2 construct for an S3 bucket sets sensible defaults; an L3 “pattern” construct builds a whole load-balanced-service). You write code, andcdk synthgenerates a CloudFormation template thatcdk deployprovisions - so CDK compiles down to CloudFormation, gaining loops, conditionals, abstraction, and IDE support while keeping CloudFormation’s provisioning engine. The exam pattern: CDK for teams who prefer defining infrastructure in familiar programming languages with reusable constructs and less boilerplate than raw CloudFormation, while still deploying via CloudFormation.

flowchart LR
  CDK[CDK code - TS/Python/Java/C#, constructs] -->|cdk synth| CFN[CloudFormation template]
  SAM[SAM template - simplified serverless] -->|transform| CFN
  CFN --> Deploy[CloudFormation provisions resources]
  TF[Terraform - multi-cloud, own state] -.alternative.-> Deploy

9.3 The Serverless Application Model (SAM)

AWS SAMis a CloudFormation extension optimized for serverless applications. A SAM template is a simplified CloudFormation template with shorthand resource types (AWS::Serverless::Function,::Api,::Table) that expand (via a transform) into full CloudFormation - so defining a Lambda + API Gateway + DynamoDB app takes far less code. TheSAM CLIalso enables local testing and debugging of serverless functions (sam local) and guided deployment. The exam pattern: SAM for concisely defining and locally testing serverless applications (Lambda/API Gateway/DynamoDB), built on top of CloudFormation - the serverless-focused IaC choice.

9.4 Choosing an IaC Tool

The decision:CloudFormation(or JSON/YAML templates) for AWS-native declarative IaC with no extra tooling - the baseline.CDKwhen you want to use a programming language with reusable constructs and abstraction, compiling to CloudFormation - great for complex infrastructure and developer teams.SAMfor serverless apps needing concise definitions and local testing.Terraformwhen you need a single cloud-agnostic tool across AWS and other clouds, accepting that you manage its state file. All provide the reviewable, version-controlled, reproducible IaC discipline; the choice is about language preference, serverless focus, and multi-cloud needs. The exam expects you to match the tool to these factors rather than treating them as interchangeable.

9.5 Banking Production Scenario

A bank standardizes on CDK for most infrastructure - platform teams write reusable L3 constructs (a compliant VPC, a hardened database, a standard microservice) in TypeScript that encode security defaults, so application teams provision to standard by composing constructs, all synthesizing to CloudFormation for provisioning. Its serverless applications use SAM for concise definitions and local testing of Lambda/API Gateway/DynamoDB stacks. A few multi-cloud edge components use Terraform. Everything flows through the CodePipeline with change-set review, and StackSets/CDK Pipelines deploy across accounts. This layered IaC approach - CDK constructs for standard infrastructure, SAM for serverless, all on CloudFormation - is exactly the professional-level infrastructure-as-code strategy the certification targets.

9.6 Chapter Revision Notes

  • CDK defines infrastructure in real languages via constructs (L1/L2/L3), then cdk synth → CloudFormation template → cdk deploy; gains abstraction/loops/IDE support on CloudFormation’s engine.
  • SAM = CloudFormation extension for serverless: shorthand resource types (Function/Api/Table) transform to CloudFormation; SAM CLI enables local testing (sam local).
  • Choose: CloudFormation (AWS-native baseline), CDK (programming languages + reusable constructs), SAM (serverless + local test), Terraform (multi-cloud, manage state).
  • All give reviewable, version-controlled, reproducible IaC; match by language preference, serverless focus, and multi-cloud needs.
  • CDK constructs encode best practices so teams provision compliant infrastructure by composition.