5

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"
                    }
                  ]
            }
        }
    }
}
Snowcrash
  • 1,087
  • 2
  • 16
  • 19

1 Answers1

8

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"
EEAA
  • 108,414
  • 18
  • 172
  • 242