EC2 Image Builderとは
AMI(Amazon Machine Image)やコンテナイメージの作成、管理、デプロイを自動化するフルマネージドサービス
“EC2 Image Builder is a fully managed AWS service that helps you to automate the creation, management, and deployment of customized, secure, and up-to-date server images.”
なぜ必要か
手動でAMIを作成・更新するのは手間がかかる:
- OSパッチの適用
- ソフトウェアのインストール・設定
- セキュリティ設定
- テスト
- 複数リージョンへの配布
Image Builderはこれらを自動化し、パイプラインとして定義できる
主な機能
自動化されたパイプライン
“Image Builder reduces the amount of work involved in creating and managing images at scale by automating your build pipelines. You can automate your builds by providing your build execution schedule preference.”
テストによる品質保証
“Image Builder provides access to test components that you can use to test your images before deployment. … Image Builder distributes your image only if all of the configured tests have succeeded.”
セキュリティ強化
“Image Builder allows you to create images that remove unnecessary exposure to component security vulnerabilities. … Image Builder also provides collections of settings for companies in regulated industries. You can use these settings to help you quickly and easily build compliant images for STIG standards.”
主要コンポーネント
イメージパイプライン
│
├── イメージレシピ / コンテナレシピ(何を作るか)
│ ├── ベースイメージ
│ └── コンポーネント(ビルド/テスト)
│
├── インフラ設定(どこで作るか)
│ ├── インスタンスタイプ
│ ├── VPC/サブネット
│ └── IAMロール
│
└── 配布設定(どこに配るか)
├── 配布先リージョン
├── AMI共有設定 / ECRリポジトリ
└── 暗号化設定
関連用語
イメージパイプライン
イメージ作成の自動化フレームワーク
“An image pipeline provides an automation framework for building secure AMIs and container images on AWS.”
イメージレシピ
ベースイメージと適用するコンポーネントを定義するドキュメント。AMI作成用
“An Image Builder image recipe is a document that defines the base image and the components that are applied to the base image to produce the desired configuration for the output AMI image.”
コンテナレシピ
Dockerコンテナイメージを作成するための設定を定義するドキュメント
出典: ContainerRecipe - EC2 Image Builder
“A ContainerRecipe is a set of instructions used to build a container image.”
イメージレシピとコンテナレシピの違い
| イメージレシピ | コンテナレシピ | |
|---|---|---|
| 出力 | AMI | Dockerコンテナイメージ |
| ベースイメージ | AMI | DockerHub、ECR、Amazon管理イメージ |
| 配布先 | 他リージョン、他アカウント | Amazon ECR |
| 追加設定 | ブロックデバイスマッピング | Dockerfileテンプレート |
“An Image Builder image recipe is a document that defines the base image and the components that are applied to the base image to produce the desired configuration for the output AMI image.”
出典: Create a new version of a container recipe
“For Docker container images, you can choose from public images hosted on DockerHub, existing container images in Amazon ECR, or Amazon-managed container images.”
コンテナレシピの構成要素
コンテナレシピ
│
├── ベースイメージ(親イメージ)
│ ├── DockerHub公開イメージ
│ ├── Amazon ECRの既存イメージ
│ └── Amazon管理コンテナイメージ
│
├── コンポーネント
│ ├── ビルドコンポーネント
│ └── テストコンポーネント
│
├── Dockerfileテンプレート
│
├── インスタンス設定(ビルド用EC2)
│
└── ターゲットリポジトリ(ECR)
Dockerfileテンプレート
コンテナレシピでは、Dockerfileテンプレートを使ってイメージのビルド方法を定義する。Image Builderが提供する変数を使用できる
出典: Create a new version of a container recipe
# 親イメージ(必須)
FROM {{{ imagebuilder:parentImage }}}
# 環境設定(コンポーネント使用時は必須)
{{{ imagebuilder:environments }}}
# コンポーネントの実行(任意)
{{{ imagebuilder:components }}}| 変数 | 説明 |
|---|---|
{{{ imagebuilder:parentImage }}} | ベースイメージに置換される(必須) |
{{{ imagebuilder:environments }}} | コンポーネント実行用スクリプト(コンポーネント使用時は必須) |
{{{ imagebuilder:components }}} | ビルド/テストコンポーネントのスクリプト |
コンテナレシピの前提条件
コンテナイメージパイプラインを作成する前に、ターゲットとなるECRリポジトリを作成しておく必要がある
出典: Get set up to build custom images with Image Builder
“For container image pipelines, a target container repository must be created before a container recipe is created. Amazon Elastic Container Registry (ECR) is used as the target repository for container images.”
コンポーネント
ビルドやテストで実行するスクリプト。YAML形式で定義
- AWSマネージドコンポーネント(パッチ適用、STIG準拠など)
- カスタムコンポーネント(独自スクリプト)
ディストリビューション設定(配布設定)
ビルドしたイメージをどこに配布するかを定義する設定
出典: Manage Image Builder distribution settings
AMI配布でできること
出典: Manage Image Builder distribution settings
“Specify the name and description of your output AMI. Authorize other AWS accounts, organizations, and OUs to launch the AMI from the owner’s account. … Copy the AMI to the owner’s account in other AWS Regions.”
- 出力AMIの名前と説明を指定
- 他のAWSアカウント、Organizations、OUにAMI起動を許可
- 他リージョンにAMIをコピー
- VMイメージディスクをS3にエクスポート
コンテナイメージ配布でできること
出典: Manage Image Builder distribution settings
“Specify the ECR repository where Image Builder stores the output image in the distribution Region.”
- 配布先リージョンのECRリポジトリを指定
ビルドの流れ
1. ビルドステージ
└── ビルドフェーズ: コンポーネント実行、ソフトウェアインストール
└── 検証フェーズ: 設定の検証
2. テストステージ
└── テストフェーズ: テストコンポーネント実行
3. 配布
└── 指定リージョンにAMI/コンテナイメージを配布
対応OS
| OS | バージョン |
|---|---|
| Amazon Linux | 2, 2023 |
| Windows Server | 2012 R2, 2016, 2019, 2022, 2025 |
| Ubuntu | 18.04, 20.04, 22.04, 24.04 LTS |
| RHEL | 7, 8, 9, 10 |
| SUSE | 12, 15, 16 |
| macOS | 12.x〜26.x |
料金
Image Builder自体は無料。ただし、ビルド中に使用するリソース(EC2インスタンス、EBSスナップショット、S3など)には通常料金がかかる
ユースケース
- ゴールデンイメージの作成・維持
- セキュリティパッチの自動適用
- コンプライアンス準拠イメージの作成(STIG等)
- マルチリージョンへのAMI配布
- CI/CDパイプラインとの統合