AWS Builder Center
Automate AMI and Container Image Creation with EC2 Image Builder

Automate AMI and Container Image Creation with EC2 Image Builder

Stop building golden images by hand: learn how EC2 Image Builder automates, tests and distributes secure AMIs and container images, with a full video walkthrough.

Hi guys
How do you build the base images for your EC2 instances today? If the answer involves launching an instance, installing packages by hand, running a few scripts and clicking "Create image"... this article is for you.
Keeping golden images up to date, patched and consistent across accounts and regions is one of those tasks that looks simple but quickly becomes toil. And toil is exactly what we, as SREs, want to eliminate.

What is EC2 Image Builder?

EC2 Image Builder is a fully managed AWS service that automates the creation, maintenance, validation and distribution of AMIs and container images (Docker). There is no extra charge for the service itself: you only pay for the underlying resources used during the build (EC2 instances, storage, etc.).

Main concepts

  • Components: the building blocks of your image. A component is a YAML document that defines build steps (install packages, apply hardening, configure agents) and test steps. You can use AWS-managed components or create your own.
  • Image recipe / Container recipe: the source image (for example, Amazon Linux 2) plus the list of components to apply.
  • Infrastructure configuration: where and how the build runs: instance type, subnet, security group, IAM instance profile and where to send logs (S3).
  • Distribution settings: where the final image goes: other AWS regions, other accounts, launch permissions or an Amazon ECR repository for container images.
  • Image pipeline: ties everything together and runs on a schedule, manually, or when new base image updates are available.

How the flow works

  1. Image Builder launches a temporary build instance from your source image.
  1. It runs the build phase of each component.
  1. It creates a snapshot and launches a separate test instance to run the test phase.
  1. If all tests pass, the image is distributed to the configured regions/accounts and the temporary resources are cleaned up.

Why use it?

  • Consistency: every image is built the same way, from versioned recipes.
  • Security: keep images patched automatically and apply hardening (such as CIS/STIG components) by default.
  • Less toil: no more manual "click-ops" to create AMIs.
  • Integration: works with AWS Systems Manager, AWS Organizations, Amazon ECR, Amazon Inspector and can be managed with CloudFormation or Terraform.

Demo

In the video below I explain the concepts and show, step by step, how to automate image creation with EC2 Image Builder:

Hands-on lab

Want to try it yourself? Here is the Git repository I used in the video, so you can follow along and build your own image pipeline:

References

Enjoy!
PS.: I recorded the video in Brazilian Portuguese, but you can use the Closed Captions feature to choose the subtitle language you prefer.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article