Infrastructure as code and CI/CD
DEA-C01 · Lesson 7 of 23 · 45:22
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the DEA-C01 exam (AWS Certified Data Engineer – Associate). In this lesson: software engineering practices for data pipelines (Git, tests, logging, monitoring), CloudFormation templates and the AWS CDK, change sets and drift detection, AWS SAM with sam build and sam deploy, CI/CD with CodePipeline and CodeBuild, and protecting production with a test stack, integration tests, and a manual approval. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Fixed by hand, lost by deploy
Last month, an engineer of AnyCompany Games changed a Glue job directly in the console, and the next deployment silently erased the fix. Nobody knew which version ran in production, and the test environment no longer matched it. This lesson covers software engineering practices for data, infrastructure as code with CloudFormation, the CDK, and AWS SAM, and continuous integration and delivery.
Engineering practices
Data pipelines are software, and the same practices apply. Version control keeps every job script, SQL query, and template in a Git repository, with branches, reviews, and a full history, so that any change can be traced and rolled back. Tests check the code before it runs on real data: unit tests on transformation functions with small sample files, and integration tests on a copy of the pipeline. Logging writes what each step did, like the input files, the row counts, and the errors, to CloudWatch Logs. And monitoring turns those logs and metrics into dashboards and alarms, so that a failing or slow job is noticed before the users notice it.
Infrastructure as code
Infrastructure as code describes buckets, jobs, roles, and databases in files, instead of clicking in the console. AWS CloudFormation reads a template in JSON or YAML and creates the resources as one stack, in the right order, and rolls back if a step fails. A change set previews what an update will add, change, or replace before you run it, and drift detection finds the resources that someone changed by hand. The AWS CDK lets you write the same infrastructure in Python, TypeScript, Java, and other languages, with reusable constructs, and it synthesizes a CloudFormation template. Because the same template always builds the same resources, deployments are repeatable, across environments and accounts.
AWS SAM
AWS SAM, the Serverless Application Model, is an extension of CloudFormation for serverless pipelines. Its template uses short resource types, like a serverless function, a state machine for Step Functions, or a simple DynamoDB table, next to any standard CloudFormation resource. The sam build command packages the code and its dependencies, and sam deploy uploads them and deploys the stack, with a guided mode the first time. You can also test a function locally with sam local invoke, and sync code changes quickly to a development stack. Because a SAM template is a CloudFormation template, you get change sets, rollbacks, and stacks too.
Continuous integration and delivery
Continuous integration means that every change in the Git repository is built and tested automatically, so that errors show up within minutes. Continuous delivery means that every change that passes the tests can go to production at any time, often after an approval, and continuous deployment goes further, with no approval at all. AWS CodePipeline chains the stages: source, build, test, and deploy, and it starts on each new commit. AWS CodeBuild runs the build and the tests from a buildspec file, like unit tests on the Glue scripts and a check of the SAM template. And the deploy stage deploys to a test stack first, runs integration tests on sample data, then waits for an approval before production.
A deployment flow
Here is how it fits together at AnyCompany Games: the Glue scripts, the SQL, and a SAM template that defines the Lambda functions, the state machine, and the DynamoDB table all sit in one repository. A commit starts the pipeline, CodeBuild runs the tests and packages the code, and CloudFormation deploys the changes to the test stack. After the integration tests pass and a manager approves, the same template is then deployed to production. And CloudWatch logs and alarms watch every run, so that a bad release can be rolled back to the previous version from Git.
Recap
Let's recap. Version control in Git, tests, logging, and monitoring apply to data pipelines too. CloudFormation templates and the CDK make deployments repeatable, with change sets and drift detection. AWS SAM simplifies serverless templates, and sam build and sam deploy package and deploy them. CodePipeline and CodeBuild automate continuous integration and continuous delivery. And a test stack, integration tests, and an approval protect production.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
The data team deploys the same pipeline to development, test, and production accounts. The environments keep drifting apart, because people create resources by hand. What should the data engineer do?
- Write a runbook with the console steps
- Define the pipeline as a CloudFormation stack
- Record every change with AWS Config
- Copy the Glue scripts to each account by hand
Show the answer
Define the pipeline as a CloudFormation stack
A template builds the same resources in every account, so the environments stay identical, and deployments are repeatable. “Write a runbook with the console steps” would still rely on people clicking, with the same mistakes. “Record every change with AWS Config” would only record the differences, not prevent them. And “Copy the Glue scripts to each account by hand” would copy the scripts, but not the roles, buckets, and jobs around them.
The team wants every commit to the pipeline code to run unit tests automatically, and to reach production only after a manager approves. Which combination fits?
- CodePipeline, CodeBuild tests, a manual approval
- EventBridge Scheduler that deploys every night
- A Lambda function that copies scripts to S3
- CloudFormation drift detection on each stack
Show the answer
CodePipeline, CodeBuild tests, a manual approval
CodePipeline starts on each commit, CodeBuild runs the unit tests, and a manual approval action gates production. “EventBridge Scheduler that deploys every night” would deploy on a clock, without tests or approval. “A Lambda function that copies scripts to S3” would copy code with no tests at all. And “CloudFormation drift detection on each stack” is for finding manual changes, not for deploying.
A data engineer must package and deploy three Lambda functions, a state machine, and a DynamoDB table as one serverless application, with the least template code. What should the engineer use?
- A CloudFormation template with full definitions
- A Glue workflow with conditional triggers
- Manual creation in the console, step by step
- An AWS SAM template deployed with sam deploy
Show the answer
An AWS SAM template deployed with sam deploy
A SAM template defines serverless resources with short resource types, and sam deploy packages and deploys them as one stack. “A CloudFormation template with full definitions” would work, but with much more template code. “A Glue workflow with conditional triggers” is for Glue jobs and crawlers, not for Lambda functions and tables. And “Manual creation in the console, step by step” would not be repeatable.