amazon-ec2-image-builder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAmazon EC2 Image Builder
Amazon EC2 Image Builder
Overview
概述
Domain expertise for building custom AMIs and container images with EC2 Image Builder — from the build IAM role through recipes, pipelines, distribution, and troubleshooting.
Works best with the AWS MCP server — recommended for sandboxed execution and audit logging. All guidance also works with standard AWS CLI access.
本技能提供使用EC2 Image Builder构建自定义AMI和容器镜像的领域专业知识——从构建IAM角色到配方、流水线、分发及故障排查的全流程指导。
最佳搭配 AWS MCP server —— 推荐用于沙箱执行和审计日志记录。所有指导同样适用于标准AWS CLI访问。
Guardrail — where this skill's own files live (MCP vs local install)
注意事项:本技能文件的存储位置(MCP vs 本地安装)
This skill can be loaded two ways, and they resolve the skill's own bundled
files from different places. Determine how the skill was loaded before reading
a reference or running a script:
- Loaded through the AWS MCP tool: The skill is not installed on the local filesystem. You MUST fetch each reference or script via
retrieve_skillwith theretrieve_skillparameter (e.g.file), and use the returned content. Do NOTfile="references/creating-images.md"these paths locally — they do not exist on disk.file_read - Installed locally (e.g. or
.kiro/skills/amazon-ec2-image-builder/): Read files from the local skill directory using relative paths.~/.claude/skills/amazon-ec2-image-builder/
This distinction applies only to the skill's own packaged files. User data and
session artifacts are always read from and written to the user's working
directory. Never fetch or write user data through .
retrieve_skill本技能有两种加载方式,其配套文件的存储位置不同。在查阅参考文档或运行脚本前,请先确认技能的加载方式:
- 通过AWS MCP的工具加载:技能未安装在本地文件系统中。必须通过
retrieve_skill工具并指定retrieve_skill参数(例如file)来获取每个参考文档或脚本,并使用返回的内容。请勿在本地使用file="references/creating-images.md"读取这些路径——它们不存在于本地磁盘中。file_read - 本地安装(例如或
.kiro/skills/amazon-ec2-image-builder/):使用相对路径从本地技能目录读取文件。~/.claude/skills/amazon-ec2-image-builder/
此区分仅适用于技能自身的打包文件。用户数据和会话工件始终从用户工作目录读取并写入该目录。切勿通过获取或写入用户数据。
retrieve_skillFirst decision: one-off image or recurring pipeline
首要决策:一次性镜像还是定期流水线
Ask this before creating anything — it changes what you build.
| The user wants | Do this |
|---|---|
| One custom AMI, once | Follow creating-images.md through step 7a: |
| A golden AMI that stays current (scheduled rebuilds that pick up base-image updates and patches) | An image pipeline: follow creating-images.md — the schedule is part of the create-image-pipeline call (step 7b). |
在创建任何资源前请先明确这一点——它会决定你的构建方式。
| 用户需求 | 操作方式 |
|---|---|
| 一次性创建一个自定义AMI | 遵循creating-images.md完成至步骤7a:使用配方和基础设施配置调用 |
| 创建持续更新的黄金AMI(定期重建以获取基础镜像更新和补丁) | 创建镜像流水线:遵循creating-images.md——调度配置包含在 |
Related skills — route there instead
相关技能:转至对应技能处理
| Use this skill | When the request is about |
|---|---|
| launching-ec2-instance-with-best-practices | Launching instances from an AMI the user already has |
| setting-up-ec2-instance-profiles | Instance profiles in general (not the build IAM role this skill creates) |
| aws-compute | AMI sharing, retiring, and lifecycle management; general EC2 fleet questions |
Not covered here: AMI lifecycle/retirement (route via the table above) and VM/ISO image import and export (follow the AWS documentation directly).
| 使用此技能 | 适用于以下请求场景 |
|---|---|
| launching-ec2-instance-with-best-practices | 从用户已有的AMI启动实例 |
| setting-up-ec2-instance-profiles | 通用实例配置文件(非本技能创建的构建IAM角色) |
| aws-compute | AMI共享、退役和生命周期管理;常规EC2集群问题 |
本技能不涵盖:AMI生命周期/退役管理(请根据上表转至对应技能)以及VM/ISO镜像导入导出(请直接参考AWS官方文档)。
Routing (references in this skill)
路由指引(本技能内的参考文档)
Read the matching reference before answering. The exact commands, failure fixes, and platform requirements live in the references — answering Image Builder questions from general knowledge is how agents get the details subtly wrong.
| User need | Read |
|---|---|
| Create an image or pipeline end to end: role, components, recipe, infrastructure, schedules, patching, scanning, chaining | creating-images.md |
Get the output AMI where it's needed: launch templates, SSM parameters (the service-linked role writes only under | distribution-options.md |
| A build failed, hangs, or an Image Builder API call errors | troubleshooting.md |
| Windows (exit-3010 reboots), macOS (Mac Dedicated Hosts required), container images to ECR (extra build-role policy) | other-image-types.md |
| Custom image workflows (advanced — always require an execution role) | custom-workflows.md |
Reference files carry specific ARNs, Amazon-managed resource names, and service defaults — when precision matters, confirm against the AWS documentation.
在回答问题前请先查阅对应的参考文档。具体命令、故障修复方案和平台要求均在参考文档中——仅凭通用知识回答Image Builder问题容易导致细节错误。
| 用户需求 | 查阅文档 |
|---|---|
| 端到端创建镜像或流水线:角色、组件、配方、基础设施、调度、补丁、扫描、链式构建 | creating-images.md |
将输出AMI分发至目标位置:启动模板、SSM参数(服务关联角色仅写入 | distribution-options.md |
| 构建失败、挂起或Image Builder API调用报错 | troubleshooting.md |
| Windows系统(exit-3010重启)、macOS系统(需要Mac专用主机)、推送至ECR的容器镜像(额外的构建角色策略) | other-image-types.md |
| 自定义镜像工作流(高级功能——始终需要执行角色) | custom-workflows.md |
参考文档包含特定的ARN、亚马逊托管资源名称和服务默认值——当需要精确信息时,请与AWS官方文档进行确认。
Guardrails (every workflow)
通用注意事项(所有工作流)
- Quote CLI filter values that contain spaces: . Unquoted spaces are a CLI parse error.
--filters "name=name,values=Amazon Linux 2023 x86" - Use the exact ARN each create call returns — never construct ARNs by hand.
- For a "latest" base image use an Amazon-managed image ARN with the wildcard, or an
x.x.xparameter reference where no managed image exists. Never list versions and sort them as strings — the list is not semver-ordered.ssm: - Keep architecture consistent across the base image, every component's binaries, and the infrastructure instance types. Image Builder performs no create-time validation of this; a mismatch only fails mid-build when the component runs.
- For component failures, the root cause lives in CloudWatch log group (on by default; also in the S3 logs if configured) — never in the API state. See troubleshooting.md.
/aws/imagebuilder/<image-name> - To reboot mid-build, exit the step with code (Linux) or
194(Windows). The build re-runs that same step after the reboot — not the next step — so guard it with a marker file. A plain reboot command fails the step.3010 - If a resource the user describes isn't visible to /
get-image, say you can't find it and check the Region and credentials in use — then keep troubleshooting from the user's description; a failed lookup is not proof the resource doesn't exist.get-image-pipeline - Distribution handles launch templates and SSM publishing natively (,
launchTemplateConfigurations) — never add Lambda glue or manual launch-template versions for AMI propagation.ssmParameterConfigurations - Default to: Amazon Linux 2023 base, IMDSv2 required (), and at least two instance types in the infrastructure configuration. S3 build logging is opt-in — CloudWatch logging is on regardless.
instanceMetadataOptions httpTokens=required - Check Amazon-managed components () before writing component YAML. Common needs (AWS CLI, OS updates, CloudWatch agent, STIG hardening) are already covered.
aws imagebuilder list-components --owner Amazon
- 对包含空格的CLI过滤值添加引号:。未加引号的空格会导致CLI解析错误。
--filters "name=name,values=Amazon Linux 2023 x86" - 使用每个创建调用返回的精确ARN——切勿手动构造ARN。
- 若要使用“最新”基础镜像,请使用带有通配符的亚马逊托管镜像ARN,或在无托管镜像时使用
x.x.x参数引用。切勿列出版本并按字符串排序——版本列表并非遵循语义化版本顺序。ssm: - 保持基础镜像、所有组件二进制文件和基础设施实例类型的架构一致。Image Builder不会在创建时验证这一点;架构不匹配只会在组件运行时导致构建失败。
- 对于组件失败问题,根本原因位于CloudWatch日志组中(默认启用;若配置了S3日志,也会存在于S3日志中)——而非API状态。请参阅troubleshooting.md。
/aws/imagebuilder/<image-name> - 若要在构建中途重启,请以代码(Linux)或
194(Windows)退出步骤。重启后构建会重新运行同一步骤——而非下一步骤——因此请使用标记文件进行防护。直接执行重启命令会导致步骤失败。3010 - 如果用户描述的资源无法通过/
get-image查询到,请告知用户无法找到该资源,并检查当前使用的区域和凭证——然后根据用户描述继续排查;查询失败并不证明资源不存在。get-image-pipeline - 分发功能原生支持启动模板和SSM发布(、
launchTemplateConfigurations)——切勿为AMI传播添加Lambda胶水层或手动创建启动模板版本。ssmParameterConfigurations - 默认配置:Amazon Linux 2023基础镜像、要求IMDSv2()、基础设施配置中至少包含两种实例类型。S3构建日志为可选启用——CloudWatch日志始终默认开启。
instanceMetadataOptions httpTokens=required - 在编写组件YAML前,请先查看亚马逊托管组件()。常见需求(AWS CLI、操作系统更新、CloudWatch代理、STIG加固)已被覆盖。
aws imagebuilder list-components --owner Amazon
Security considerations
安全考量
The defaults above are the security posture: IMDSv2 required on build instances, no inbound security-group rules, least-privilege build IAM role (two managed policies for AMI builds plus only the scoped grants a workflow needs), no secrets in components or logs, and log buckets with Block Public Access. Build logs capture full command output that can carry sensitive material; CloudWatch Logs encrypts them at rest by default, and associating a customer-managed KMS key with each log group () is recommended. For auditing and operational visibility, enable CloudTrail in the account so Image Builder API calls are recorded, and configure EventBridge rules or CloudWatch alarms on build failures (source , detail-type ) so misconfigurations and unauthorized changes surface promptly. Per-build notifications are covered by the SNS topic option (creating-images.md step 6) — prefer a customer-managed key on that topic too. Deviations from these should be explicit user decisions. Reference: EC2 Image Builder security best practices.
/aws/imagebuilder/...aws logs associate-kms-keyaws.imagebuilderEC2 Image Builder Image State Change上述默认配置即为安全基准:构建实例要求IMDSv2、无入站安全组规则、最小权限的构建IAM角色(AMI构建需两个托管策略,加上工作流所需的范围化权限)、组件或日志中不包含敏感信息、日志存储桶启用公共访问阻止。构建日志会捕获完整的命令输出,可能包含敏感内容;CloudWatch日志默认对静态数据进行加密,建议为每个日志组关联客户托管的KMS密钥()。为实现审计和运维可视性,请在账户中启用CloudTrail,以便记录Image Builder API调用,并针对构建失败配置EventBridge规则或CloudWatch告警(源,详细类型),从而及时发现配置错误和未授权变更。每构建一次的通知由SNS主题选项覆盖(creating-images.md步骤6)——同样建议为该主题使用客户托管密钥。偏离这些配置需由用户明确决策。参考文档:EC2 Image Builder安全最佳实践。
/aws/imagebuilder/...aws logs associate-kms-keyaws.imagebuilderEC2 Image Builder Image State Change