Specifying a VPC in a CloudFormation template for an EC2 instance
I'm launching an EC2 instance via a CloudFormation template, however, the specified instance t2.micro
requires a VPC.
How do I specify a VPC in the CloudFormation template?
Here's my template:
{
"Description" : "Single Instance",
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : "ami-b73b63a0",
"InstanceType" : "t2.micro",
"KeyName" : "my-key",
"Tags" : [
{
"Key" : "Name",
"Value" : "test"
}
]
}
}
}
}
For EC2 Instances, you get to skip specifying the VPC ID and instead, just specify the subnet you want the instance in. From there, the VPC is assumed.
Inside of your "Properties" array, add the following:
"SubnetId" : "subnet-XXXXXXXX"