Automating AMI Builds with EC2 Image Builder Pipelines
This lesson explains how EC2 Image Builder automates building, testing and distributing AMIs and container images with a managed, repeatable pipeline.
Learning outcomes
After completing this lesson, you will be able to:
- Assemble components, recipes and configurations.
- Run and test pipelines.
- Automate image retirement with lifecycle policies.
Image Builder components
An Image Builder setup is assembled from several resources. A component is a YAML document of build or test steps, such as installing packages, applying CIS hardening, or running validation commands; AWS provides managed components (for example update-linux and amazon-cloudwatch-agent-linux), and you can write your own. An image recipe combines a parent image (an AWS-managed base AMI, a Marketplace AMI or your own) with an ordered list of components and block device settings; a container recipe does the same for Docker images. An infrastructure configuration specifies the instance types, subnet, security group, instance profile (needing EC2InstanceProfileForImageBuilder and AmazonSSMManagedInstanceCore), S3 logging and SNS notifications. A distribution configuration names the target Regions and accounts, AMI name, launch permissions, KMS keys, launch template updates and SSM parameter updates, or the ECR repository for container images.
Image Builder resources
Pipelines and testing
An image pipeline runs the recipe with the infrastructure and distribution configurations manually, on a cron schedule, or when the parent image has updates (only build if dependency updates are available). Image Builder launches a build instance, applies build components through Systems Manager, creates a snapshot image, launches a test instance and runs test components, and distributes the image only if the tests pass. Image scanning with Amazon Inspector can be enabled to report vulnerabilities in each image. Pipelines can also be defined with CloudFormation, and workflows customise the build and test stages.
The following diagram shows one pipeline run and its test gate.

A pipeline run
Lifecycle policies
Image Builder lifecycle policies automate retirement of images built by Image Builder: rules based on age or count deprecate, disable or delete AMIs and their snapshots, or delete container images, with exclusion rules for tagged images that must be kept. This prevents snapshot storage growing without limit as pipelines produce new images every week. The following table summarises the Image Builder resources.
| Resource | Defines |
|---|---|
| Component | Build or test steps (YAML) |
| Image recipe / container recipe | Parent image plus ordered components |
| Infrastructure configuration | Instance type, subnet, security group, instance profile, logging, SNS |
| Distribution configuration | Regions, accounts, launch permissions, KMS keys, launch templates, SSM parameters, ECR |
| Image pipeline | Schedule and the configurations above |
| Lifecycle policy | Deprecate, disable or delete old images |
A monthly patched AMI
A team needs a CIS-hardened Amazon Linux 2023 AMI rebuilt after each monthly patch release and rolled out to Auto Scaling groups in two Regions. The recipe uses the AWS-managed AL2023 parent image with the update-linux, CIS hardening and CloudWatch agent components plus a custom test component that checks the application starts. The pipeline runs on a schedule, shares the AMI with the production accounts, copies it to the DR Region with the DR KMS key, updates the /golden/al2023/latest parameter and creates a new launch template version. A lifecycle policy keeps the last six images. An instance refresh then rolls the new AMI into each group.
What does an Image Builder recipe contain?
Show answer
A parent image and the components to apply to it.
Exam Tips
Remember for the exam
- Recipe = parent image + components; infrastructure configuration = where the build runs; distribution = where the image goes.
- Pipelines run on a schedule or when the parent image updates; tests gate distribution.
- Build instances need the Image Builder and SSM instance profile policies and a route to SSM.
- Distribution can update launch templates and SSM parameters automatically.
- Lifecycle policies deprecate and delete old images and snapshots.