Skip to content
Latchkey

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.

packer
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

  1. Replace the hardcoded id with a source_ami_filter.
  2. Filter by name, owner, and virtualization so the newest matching AMI is chosen per region.
  3. Re-run the build in the target region.
build.pkr.hcl
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.

build.pkr.hcl
source "amazon-ebs" "ubuntu" {
  region     = "us-west-2"
  source_ami = "ami-0123456789abcdef0"
}

How to prevent it

  • Prefer source_ami_filter over hardcoded region-specific ids.
  • Keep region and source AMI consistent in the template.
  • Confirm cross-account AMIs are shared with the build account.

Frequently asked questions

What causes ""InvalidAMIID.NotFound""?
An AMI id is only valid in one region. Building in us-east-1 with a us-west-2 id returns NotFound.
How do I fix "InvalidAMIID.NotFound"?
Resolve the AMI dynamically with a source filter

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card