Cloud formation templates for reusing an ALB for multiple apps
In the migration of our e-commerce site, coldstorage.com.sg to AWS, we have another small legacy app hosted on onenorth.coldstorage.com.sg that needs to move as well. However, due to the low traffic of this app, we decide to reuse the ALB of coldtorage.com.sg, so that the AWS Certificate Manager can deploy the SSL cert automatically.
Firstly, we create another TargetGroup,
"ALBTargetGroupCSOnline": { "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", "Properties": { "HealthCheckIntervalSeconds": 10, "HealthCheckTimeoutSeconds": 5, "HealthyThresholdCount": 2, "Port": 80, "Protocol": "HTTP", "UnhealthyThresholdCount": 5, "VpcId": { "Ref": "VPCId" }, "Targets": [ { "Id" : {"Ref" : "CSOnlineWebServer1"}, "Port" : 80 }, { "Id" : {"Ref" : "CSOnlineWebServer2"}, "Port" : 80 } ], "TargetGroupAttributes": [ ...... ] } }, "ALBTargetGroupCSOneNorth": { "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", "Properties": { "HealthCheckIntervalSeconds": 10, "HealthCheckTimeoutSeconds": 5, "HealthyThresholdCount": 2, "Port": 80, "Protocol": "HTTP", "UnhealthyThresholdCount": 5, "VpcId": { "Ref": "VPCId" }, "Targets": [ { "Id" : {"Ref" : "CSOneNorthWebServer"}, "Port" : 80 } ], "TargetGroupAttributes": [ ...... ] } }, Then, creating a Listener rule for it and attach it to the HTTPS listener. The rule will forward the requests whose host-header matches the value specified, e.g. for our case, “onenorth.coldstorage.com.sg”. Otherwise, default routing will be applied.
This is an excerpt — the full article continues on Medium.
Read the full article on Medium →