Defining Data Platforms with Infrastructure as Code and AWS SAM
This lesson explains how infrastructure as code (IaC) defines data platforms in version-controlled templates, so environments are repeatable, reviewable and easy to roll back.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish CloudFormation, AWS SAM and the AWS CDK.
- Describe the SAM CLI commands.
- Identify the benefits of IaC for data platforms.
IaC tools
Infrastructure as code (IaC) defines buckets, Glue jobs, streams and roles in files, so every environment is built the same way and changes are reviewed like code. AWS CloudFormation is the foundation: templates in JSON or YAML describe resources, parameters supply values that differ per environment, change sets preview what a deployment will change, and StackSets deploy to many accounts and Regions.
The AWS CDK (Cloud Development Kit) writes infrastructure in Python or TypeScript and generates CloudFormation. Its high-level constructs apply sensible defaults, loops and classes remove repetition, and helpers such as bucket.grantRead(role) write least-privilege policies. AWS SAM (Serverless Application Model) extends CloudFormation with short resource types for functions, state machines and tables, simple event source syntax and policy templates, which suits serverless pipelines. The following table summarises the tools.
| Tool | What it does |
|---|---|
| AWS CloudFormation | Describes resources (buckets, Glue jobs and crawlers, Redshift, Kinesis, IAM, Step Functions) in JSON or YAML; parameters per environment, change sets to preview, StackSets for many accounts and Regions |
| AWS CDK | Infrastructure in Python or TypeScript with high-level constructs; loops and classes reduce repetition; helpers like bucket.grantRead(role) write least-privilege policies |
| AWS SAM | A CloudFormation extension for serverless pipelines: AWS::Serverless::Function, StateMachine, SimpleTable, short event source syntax and policy templates |
CloudFormation, CDK or SAM?
The SAM CLI
The SAM command line interface (CLI) supports the whole development cycle. sam build prepares the code and its dependencies, and sam deploy deploys the application through CloudFormation. sam local invoke runs a function on your own computer in a container that imitates Lambda, so you can test it with a sample event before deploying. sam sync, known as SAM Accelerate, quickly pushes code changes to a development stack in the cloud, often without a full deployment, for fast iteration. The following table summarises the commands.
| Command | Purpose |
|---|---|
sam build, sam deploy | Build and deploy |
sam local invoke | Test functions locally |
sam sync (SAM Accelerate) | Fast iteration against the cloud |
The following diagram shows one infrastructure template deployed to three environments.

SAM CLI commands
Benefits of IaC
Data platforms contain many resources: buckets, Glue jobs and crawlers, Step Functions workflows, Lambda functions, Redshift workgroups, IAM roles and Lake Formation permissions. Created by hand in the console, these drift apart between environments, and nobody can say exactly how production was built. Infrastructure as code (IaC) describes them in templates or code instead.
The benefits follow directly. Development, test and production environments are created from the same definitions, so a pipeline that works in test behaves the same way in production. Infrastructure changes are reviewed like code and deployed automatically through CI/CD pipelines. If a deployment fails, AWS CloudFormation rolls it back to the previous state; drift detection reveals changes made outside the templates; and the templates themselves are a reliable record of what exists and why.
Why use IaC
The same pipeline in three environments
A team's pipeline (S3 buckets, Glue jobs, a Step Functions state machine, IAM roles) was built by hand in production, and the test environment differs in small ways that cause surprises.
| With infrastructure as code | Benefit |
|---|---|
| One CloudFormation or CDK template with an environment parameter | Dev, test and prod are identical except for names and sizes |
| Templates in Git, changed by pull request | Every change is reviewed and recorded |
| Deployed by a pipeline | No manual steps; rollback to the previous version |
| Glue job scripts packaged with the template | Code and infrastructure versioned together |
For a pipeline built mostly from Lambda functions and Step Functions, AWS SAM shortens the templates and adds local testing with sam local invoke.
How can infrastructure changes be previewed before they are applied?
Show answer
With CloudFormation change sets.
Exam Tips
Remember for the exam
- To package and deploy serverless pipelines built on Lambda and Step Functions, use AWS SAM.
- To define infrastructure in Python or TypeScript, use the AWS CDK.
- To preview infrastructure changes before applying them, use CloudFormation change sets.
- To deploy the same stack to many accounts and Regions, use StackSets.
- To test Lambda functions locally, use sam local invoke.