About reusing vpcs, security groups and route53 zones when deploying new stacks
Posted by Daniel Viorreta on May 18, 2015
Amazon VPCs lets create your own isolated section in AWS in your own virtual network.
I have only one VPC and its subnets created in my production environment. Then I have different stacks with my production services that use them. A new deployment of my application consists in deploying new stacks using the VPC deployed previously and delete the old stacks without modifying the VPC. The problem is how to identify the VPC where I want to deploy my new stacks without deploying a new VPC each time that I have a new version of my code. Similar for security groups and route53 private zones.
Tagging VPCs and subnets
To identify my VPC and my subnet I use a label to tag them. This is a part of a cloudformation where I tag the VPC and one of its subnets. Assume than we pass labelstack as a cloudformation parameter:
Note that we can do something similar to security groups.
Getting VPCs, subnets and route53 zones by tag name
Then, via boto I can get the vpcs and subnet using the labelstack to identify them. Similar for security groups and route53 private zones.
This is the ‘api’ that our class will have to implement:
And this is an implementation of it:
Now, each time that I deploy a new version on my application a pass the parameter whith the label where I want to attach the stacks.