How to create an Amazon VPC using AWS CloudFormation?

Anand Soni picture Anand Soni · Apr 11, 2012 · Viewed 10.2k times · Source

I am currently using AWS CloudFormation for my application. Right now I am able to auto scale the instances. Now, I want to put every thing on an Amazon VPC. Can we create a VPC using CloudFormation? And how can we manage the Elastic IP address via CloudFormation, when we have an ELB in the template? I have found a VPC related example on AWS CloudFormation Sample Templates, but it only provisions resources into an existing VPC and doesn't create a new one in the template.

Answer

Steffen Opel picture Steffen Opel · Apr 12, 2012

Update

As pointed out by Jeff already (+1), AWS has just announced AWS CloudFormation Support for Creating VPC Resources as of April 25, 2012, covering the missing piece of their initial VPC support:

We are excited to announce that AWS CloudFormation now supports the creation of Amazon Virtual Private Cloud (VPC) resources. [...]

Now, you can create new Virtual Private Clouds (VPC), subnets, gateways, network ACLs, routes and route tables using CloudFormation templates. [...]

[...] A CloudFormation can now fully represent your VPC configuration along with all the resources needed to run your application in the VPC.

See Jeff Barr's introductory post AWS CloudFormation Can Now Create Virtual Private Clouds for more details and examples. In particular, the AWS CloudFormation Sample Templates feature two new sample templates [...] to get you started as well:


Initial Answer

I don't think creating an Amazon VPC with AWS CloudFormation is already supported.

While AWS has just announced AWS CloudFormation Support For VPC as of February 12, 2012 indeed, this covers existing resource types only:

All resource types such as Amazon EC2 instances, security groups and Elastic IP addresses, Elastic Load Balancers, Auto Scaling Groups and Amazon RDS Database instances can now be deployed into any existing Amazon VPC using CloudFormation templates. The templates allow you to run multi-tier web applications and corporate applications in a private network. With Amazon VPC and CloudFormation, you can easily control which resources you want to expose publicly and which ones should be private.

Amazon VPC is notably absent from this list, which matches the fact that it isn't listed in the supported AWS Resource Types Reference either.