evandbrown/aws-hangouts — pull request #3 by anthroprose (2014-01-24 15:31:12+00:00)
Title: Scalable Subnet Patterns

Below are some examples of scalable methods I have developed on my own. They do however require editing when moving between regions to account for zone # differences, and search/replacing the second octet of subnets in order to move between regions or create a staging environment.

IE. us-east-1 = 10.1.0.0, us-west-1 = 10.2.0.0, etc..

Is this a case for using the new conditionals and simply having logic on almost every element of my subnet template or do you have any better suggestions?

I make subnets in 'triplets' due to HEAVY use of ASG for 1:1 single instance uptime use as well as true ASG responsive groups in addition to AWS Internal services like ElastiCache, ELB, RDS when used inside of a VPC.

```json
"Mappings" : {

"AWSRegionAvailabilityZones" : {
"us-east-1" : { "1" : "us-east-1a", "2" : "us-east-1d", "3" : "us-east-1c", "4" : "us-east-1d" },
"us-west-1" : { "1" : "us-west-1a", "2" : "us-west-1b", "3" : "us-west-1c" },
"us-west-2" : { "1" : "us-west-2a", "2" : "us-west-2b", "3" : "us-west-2c" }
}

},

"Resources" : {

"PublicSubnet0" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "1" ]},
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.1.0.0/27"
}
},

"PublicSubnet1" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "2" ]},
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.1.0.32/27"
}
},

"PublicSubnet2" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "3" ]},
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.1.0.64/27"
}
},

"PrivateSubnet0" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "1" ]},
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.1.0.96/27"
}
},

"PrivateSubnet1" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "2" ]},
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.1.0.128/27"
}
},

"PrivateSubnet2" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "3" ]},
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.1.0.160/27"
}
},

"IntakeELB": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"Subnets" : [{ "Ref" : "PublicSubnet0" }, { "Ref" : "PublicSubnet1" }, { "Ref" : "PublicSubnet2" }],
"SecurityGroups" : [ { "Ref" : "ELBSecurityGroup" } ],
"Listeners": [{
"LoadBalancerPort": "80",
"InstancePort": "80",
"Protocol": "HTTP"
}],
"HealthCheck": {
"Target": "HTTP:80/heartbeat",
"HealthyThreshold": "2",
"UnhealthyThreshold": "2",
"Interval": "30",
"Timeout": "5"
}
}
},

"CacheSubnetGroup" : {
"Type" : "AWS::ElastiCache::SubnetGroup",
"Properties" : {
"Description" : "Subnets available for the ElastiCache Cluster",
"SubnetIds" : [{ "Ref" : "PrivateSubnet0" }, { "Ref" : "PrivateSubnet1" }, { "Ref" : "PrivateSubnet2" }]
}
},

"IntakeASGServerGroup" : {
"UpdatePolicy" : {
"AutoScalingRollingUpdate" : { "MinInstancesInService" : { "Ref" : "IntakeASGMin" }, "MaxBatchSize" : "1" }
},
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : [{ "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "1" ]}, { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "2" ]}, { "Fn::FindInMap" : [ "AWSRegionAvailabilityZones", { "Ref" : "AWS::Region" }, "3" ]}],
"VPCZoneIdentifier" : [{ "Ref" : "PrivateSubnet0" }, { "Ref" : "PrivateSubnet1" }, { "Ref" : "PrivateSubnet2" }],
"LaunchConfigurationName" : { "Ref" : "IntakeLaunchConfig" },
"LoadBalancerNames" : [ { "Ref" : "IntakeELB" } ],
"MinSize" : { "Ref" : "IntakeASGMin" },
"MaxSize" : { "Ref" : "IntakeASGMax" },
"DesiredCapacity" : { "Ref" : "IntakeASGDesired" },
"NotificationConfiguration" : {
"TopicARN" : { "Ref" : "MessageTopic" },
"NotificationTypes" : ["autoscaling:EC2_INSTANCE_LAUNCH", "autoscaling:EC2_INSTANCE_LAUNCH_ERROR", "autoscaling:EC2_INSTANCE_TERMINATE", "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"]
},
}
},

}
```