Your nightly golden-AMI pipeline shows FAILED, the console message is vague, and the build instance has already been terminated. This guide gets you from "it failed" to the failing step and the real error message, then covers the causes that account for most failures.
Symptom → cause → fix
| Symptom / message | Likely cause | Fix |
|---|---|---|
| Build fails within the first minutes, nothing in component logs | Build instance never registered with SSM | Instance profile, SSM endpoints or NAT, SSM Agent on the base AMI |
Component step ExecuteBash / ExecutePowerShell failed | Your script returned non-zero | Read the TOE log, reproduce with awstoe run |
| Access denied downloading components or files | Instance profile can't read S3 or ECR | Add EC2InstanceProfileForImageBuilder (or the ECR variant) plus your bucket |
| Build passes, test phase fails | Test component failed on the new AMI | Check the test instance logs; a reboot or service test usually shows the problem |
| Distribution fails | KMS key or cross-account / cross-Region sharing permissions | Grant the Image Builder service-linked role use of the key in each target Region |
InsufficientInstanceCapacity | Single instance type in one AZ | List several instance types in the infrastructure configuration |
Step 1: find the failed image and its reason
Every pipeline run creates an image build version. Start there.
aws imagebuilder list-image-pipelines \
--query 'imagePipelineList[].{name:name,arn:arn,status:status}' --output table
PIPE=arn:aws:imagebuilder:eu-west-1:111122223333:image-pipeline/golden-al2023
aws imagebuilder list-image-pipeline-images --image-pipeline-arn "$PIPE" \
--query 'imageSummaryList[].{arn:arn,status:state.status,reason:state.reason}' \
--output table
Take the ARN of the failed build version and read its state:
IMG=arn:aws:imagebuilder:eu-west-1:111122223333:image/golden-al2023/1.0.0/42
aws imagebuilder get-image --image-build-version-arn "$IMG" --query 'image.state'
The reason often contains Workflow Execution ID: wf-... failed with reason: .... That ID is your way into the step-level detail.
Step 2: drill into the workflow steps
aws imagebuilder list-workflow-executions --image-build-version-arn "$IMG" \
--query 'workflowExecutions[].{id:workflowExecutionId,type:type,status:status,msg:message}' \
--output table
aws imagebuilder list-workflow-step-executions --workflow-execution-id wf-0123456789abcdef \
--query 'steps[].{step:name,action:action,status:status,msg:message}' --output table
The first step with FAILED tells you which phase broke: launching the build instance, running components, creating the AMI, launching the test instance, or distributing. Use get-workflow-step-execution --step-execution-id <id> to see the inputs and outputs of that step, such as the instance ID that was launched.
Step 3: read the component logs
Image Builder streams the AWSTOE component logs to CloudWatch Logs. The log group is named after the image; list it rather than guessing:
aws logs describe-log-groups --log-group-name-prefix /aws/imagebuilder/ \
--query 'logGroups[].logGroupName'
aws logs tail /aws/imagebuilder/golden-al2023 --since 6h --format short
AWSTOE writes the first failed step and its full stderr near the end of the stream. If you configured S3 logging in the infrastructure configuration, the same logs are under the S3 prefix you set.
On the instance itself, TOE logs live under /var/lib/amazon/toe/ on Linux and C:\ProgramData\Amazon\TOE\ on Windows.
Keep the failed instance for debugging
By default Image Builder terminates the build instance on failure. Turn that off while you debug:
INFRA=arn:aws:imagebuilder:eu-west-1:111122223333:infrastructure-configuration/golden-infra
aws imagebuilder get-infrastructure-configuration --infrastructure-configuration-arn "$INFRA" \
--query 'infrastructureConfiguration.{profile:instanceProfileName,types:instanceTypes,subnet:subnetId,sgs:securityGroupIds,terminate:terminateInstanceOnFailure,logs:logging}'
Warning
update-infrastructure-configurationreplaces the whole configuration. Pass every field you want to keep: instance types, subnet, security groups, logging, SNS topic and key pair. Anything you leave out is cleared, and the next build may land in the default VPC.
aws imagebuilder update-infrastructure-configuration \
--infrastructure-configuration-arn "$INFRA" \
--instance-profile-name ImageBuilderInstanceRole \
--instance-types m7i.large m6i.large \
--subnet-id subnet-0abc1234 --security-group-ids sg-0abc1234 \
--logging '{"s3Logs":{"s3BucketName":"my-ib-logs","s3KeyPrefix":"golden-al2023"}}' \
--no-terminate-instance-on-failure
Turn termination back on when you're done, or stopped build instances will pile up.
Cause 1: build instance never reaches SSM
Image Builder drives the build through Systems Manager. If the instance can't register, the build times out with no component output.
Check:
- Instance profile includes
AmazonSSMManagedInstanceCoreandEC2InstanceProfileForImageBuilder(orEC2InstanceProfileForImageBuilderECRContainerBuildsfor container recipes). - Network path: the subnet needs a route to the SSM endpoints (
ssm,ssmmessages,ec2messages) and to S3, through a NAT gateway or VPC endpoints. A private subnet with no NAT and only an S3 gateway endpoint is a common gap. - Security group allows outbound HTTPS (443).
- Base AMI has the SSM Agent installed and starts it. Hardened or third-party images sometimes don't.
While the instance is still running, confirm registration:
aws ssm describe-instance-information \
--filters Key=InstanceIds,Values=i-0123456789abcdef0 \
--query 'InstanceInformationList[].{id:InstanceId,ping:PingStatus,agent:AgentVersion}'
An empty result means it never registered. Look at the console output for agent errors:
aws ec2 get-console-output --instance-id i-0123456789abcdef0 --latest --output text | tail -50
Cause 2: your component script failed
Most failures are ordinary script bugs: a package repository was unreachable, a command needs sudo, or a step expects a file from an earlier step that didn't exist. Reproduce locally on a test instance from the same base AMI instead of re-running the full pipeline each time:
awstoe validate --documents ./harden-al2023.yml
awstoe run --documents ./harden-al2023.yml --phases build
Things that catch people out:
- A step fails if the script exits non-zero. A final
grepthat finds nothing, or atestthat returns false, counts as a failure. - Components that need a reboot should use the
Rebootaction (or AWSTOE's documented reboot exit code), not a restart called from inside a script. A restart that AWSTOE didn't request interrupts the run. - Interactive installers hang until the step times out. Use silent or non-interactive flags.
Cause 3: the test phase fails
The test phase launches a new instance from the freshly created AMI and runs your test components. If the build passed but the test fails, the AMI itself is the problem: a service that doesn't start after reboot, a broken fstab entry, or a hardening step that blocked SSM. Read the test instance's TOE logs the same way, and check get-console-output for boot errors.
Cause 4: distribution fails
Distribution copies and shares the AMI. Failures here usually come from encryption and sharing:
- Encrypted AMIs distributed to another Region need a KMS key there, and the Image Builder service-linked role (
AWSServiceRoleForImageBuilder) must be allowed to use it. - Sharing to other accounts with a customer managed key requires those accounts to be allowed to use the key. Otherwise they can see the AMI but can't launch from it.
- Distribution into other accounts (rather than just sharing launch permissions) needs the cross-account distribution role set up in each target account.
aws imagebuilder get-distribution-configuration \
--distribution-configuration-arn arn:aws:imagebuilder:eu-west-1:111122223333:distribution-configuration/golden-dist \
--query 'distributionConfiguration.distributions[].{region:region,kms:amiDistributionConfiguration.kmsKeyId,share:amiDistributionConfiguration.launchPermission}'
Re-run the pipeline
After fixing the cause:
aws imagebuilder start-image-pipeline-execution --image-pipeline-arn "$PIPE"
Then watch the new image version with list-image-pipeline-images until it reaches AVAILABLE.
Prevent it next time
- Set an SNS topic in the infrastructure configuration, or create an EventBridge rule on Image Builder image state changes, so failures page someone instead of being discovered at patch time.
- Keep S3 logging enabled. CloudWatch log retention and S3 lifecycle rules then decide how long you keep them.
- List two or three instance types so a capacity shortage in one type doesn't fail the build.
- Validate components with
awstoe validatein CI before you publish a new component version. - Build in a dedicated subnet with tested SSM and S3 connectivity, and don't share it with workloads that change network rules.
- Pin component versions in recipes (for example
1.2.xrather thanx.x.x) so a new component version doesn't break the pipeline overnight.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get