Packer "InvalidAMIID.NotFound" source AMI error in CI
AMIs are region scoped. If the source AMI id belongs to a different region, was deregistered, or is not shared with your account, AWS returns InvalidAMIID.NotFound when Packer looks it up.
What this error means
packer build fails with "InvalidAMIID.NotFound: The image id does not exist" while resolving the source image for the builder.
Error: Error querying AMI: InvalidAMIID.NotFound: The image id '[ami-0123456789abcdef0]'
does not exist
status code: 400, request id: ...Common causes
The AMI id is from another region
An AMI id is only valid in one region. Building in us-east-1 with a us-west-2 id returns NotFound.
The AMI was deregistered or is not shared
A hardcoded id may have been deleted, or a cross-account AMI is not shared with your account.
How to fix it
Resolve the AMI dynamically with a source filter
- Replace the hardcoded id with a
source_ami_filter. - Filter by name, owner, and virtualization so the newest matching AMI is chosen per region.
- Re-run the build in the target region.
source_ami_filter {
filters = { name = "ubuntu/images/*22.04-amd64-server-*" }
owners = ["099720109477"]
most_recent = true
}Match the region to the AMI id
If you must pin an id, set the builder region to the one where that AMI exists.
source "amazon-ebs" "ubuntu" {
region = "us-west-2"
source_ami = "ami-0123456789abcdef0"
}How to prevent it
- Prefer
source_ami_filterover hardcoded region-specific ids. - Keep region and source AMI consistent in the template.
- Confirm cross-account AMIs are shared with the build account.