Search code examples
amazon-web-servicesamazon-ec2amazon-ami

Terraform - Can't install "aws linux ami" using t2.micro instance type


I'm trying to install "aws linux ami" ami from North Virginia, using instance type of t2.micro, but I can't find ami for "aws linux ami" of virtualization type of "hvm" (I find only of type pv). Is there no way to install "aws linux ami" of type t2?

I ran the following tf:

provider "aws" {
  access_key = "AKIAJHBBU5KDBVL26TBA"
  secret_key = "E3L4+tuTxQKdf+iD3wbWHg6FsHxB+9169ZT7Q4NL"
  region     = "us-east-1"
}

resource "aws_instance" "example" {
  ami           = "ami-2d387344"
  instance_type = "t2.micro"
}

* This is the only ami I find for "aws linux ami" in N. Virginia, but its "Virtualization type: paravirtual" so I get the following errors:

 aws_instance.example: Error launching source instance: InvalidParameterCombination: Virtualization type 'hvm' is required for instances of type 't2.micro'.

Only when I use t1.micro, it works.

I'm very new with AWS, am I missing something, or there is really no way to run "aws linux ami" of type t2?


Solution

  • You can search for the AMI ids using the AWS cli:

    aws ec2 --profile prof describe-images 
    --owners amazon
    --filters 
    'Name=name,Values=amzn2-ami-hvm-2.0.????????-x86_64-gp2' 'Name=state,Values=available'
    --output json | jq -r '.Images | sort_by(.CreationDate) | last(.[]).ImageId'
    

    This returns:

    ami-09def150731bdbcc2

    For your use case pass in --region us-east-1 as well.