How to fix Error launching source instance: InvalidAMIID.NotFound in Terraform
This error occurs when Terraform attempts to launch an EC2 instance using an AMI ID that doesn't exist in the specified AWS region. The most common cause is using an AMI ID from a different region, as AMI IDs are region-specific.
Quick fix
Fixes InvalidAMIID.NotFound
provider "aws" {
region = "us-west-2"
}- Verify the current AWS region in Terraform
- Confirm the AMI ID exists in your region
- Use the aws_ami data source for region-independent AMI selection (Recommended)
- Manually update the AMI ID if you need a specific image
provider "aws" {region = "us-west-2"}Error launching source instance: InvalidAMIID.NotFound
What this error means
The InvalidAMIID.NotFound error indicates that AWS cannot find the specified Amazon Machine Image (AMI) ID in the configured region. AMI IDs are unique identifiers for virtual machine templates, and each one is tied to a specific AWS region. When you change your Terraform configuration to use a different region or specify an incorrect AMI ID, AWS will reject the request because the image doesn't exist in that location.
Typical symptoms
- Terraform apply fails with 'InvalidAMIID.NotFound' message
- EC2 instance creation halts during infrastructure deployment
- terraform refresh fails for aws_launch_configuration resources
- Error message includes the specific AMI ID that was not found (e.g., ami-0c55b159cbfafe1f0)
Common causes
- Region mismatch: The AMI ID exists in a different AWS region than the one configured in Terraform
- Deleted or deregistered AMI: The specified AMI has been removed from AWS
- Typo in AMI ID: The AMI identifier was mistyped or copied incorrectly
- Architecture mismatch: Using an ARM-based AMI with an x86 instance type (or vice versa)
- Insufficient IAM permissions: The AWS account lacks permission to access the specified AMI
How to fix "Error launching source instance: InvalidAMIID.NotFound"
Check your Terraform configuration or environment for the configured AWS region. Look for:
provider "aws" {
region = "us-west-2"
}Or check your environment: echo $AWS_REGION
Log into the AWS EC2 Console, switch to the same region as your Terraform config, and search for the AMI ID in "Images" > "AMIs". If the AMI doesn't appear, it's not available in that region.
Replace hardcoded AMI IDs with the aws_ami data source, which automatically selects the correct AMI for your region:
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
}If you require a particular AMI, go to the AWS EC2 Console, find the correct AMI ID in your target region, and update your Terraform code:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0" # Updated for your region
instance_type = "t3.micro"
}If you're working with aws_launch_configuration and the AMI has been deleted, you may need to remove it from state:
terraform state rm aws_launch_configuration.example
terraform applyThis will cause Terraform to recreate the launch configuration with the new AMI.
Advanced notes
AMI IDs follow the format ami-XXXXXXXX and are unique per region. When using Terraform across multiple environments or regions, the aws_ami data source is strongly recommended as it handles region differences transparently. Some organizations use custom AMIs stored in their own AWS accounts; ensure your IAM role has ec2:DescribeImages permissions to access these. For deleted AMIs in terraform state, you can bypass the error temporarily with 'terraform state rm' but should update your configuration to reference valid AMIs. Consider using AWS Systems Manager Parameter Store to centralize AMI ID management across your infrastructure.
Frequently asked questions
- What does "InvalidAMIID.NotFound" mean?
- NotFound error indicates that AWS cannot find the specified Amazon Machine Image (AMI) ID in the configured region. AMI IDs are unique identifiers for virtual machine templates, and each one is tied to a specific AWS region. When you change your Terraform configuration to use a different region or specify an incorrect AMI ID, AWS will reject the request because the image doesn't exist in that location.
- How do I fix "InvalidAMIID.NotFound"?
- This error occurs when Terraform attempts to launch an EC2 instance using an AMI ID that doesn't exist in the specified AWS region. The most common cause is using an AMI ID from a different region, as AMI IDs are region-specific.
- What causes "InvalidAMIID.NotFound"?
- Region mismatch: The AMI ID exists in a different AWS region than the one configured in Terraform Deleted or deregistered AMI: The specified AMI has been removed from AWS Typo in AMI ID: The AMI identifier was mistyped or copied incorrectly
- Is the "InvalidAMIID.NotFound" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.