I'm building a CloudFormation stack. I have
- a web app in an ECS container which has
PortMappings
forContainerPort
s 9000 and 9002, mapped toHostPort
s 80 and 443, and - an application load balancer (
AWS::ElasticLoadBalancingV2::LoadBalancer
) withListener
s andTargetGroup
s for HTTP on port 80 and HTTPS on port 443
When I define a Service
, I can only specify one load balancer element; although LoadBalancers
is plural, documentation says only one load balancer is allowed, and specifying two load balancer elements doesn't work. How, then, to map both ports?
Here's the service part of my CloudFormation JSON with only the HTTPS parts, which works. Can it be extended to route HTTP to the same container? If not, what's the best solution?
"Service": {
"Type": "AWS::ECS::Service",
"DependsOn": ["AutoScalingGroup", "HTTPSListener"],
"Properties": {
"Cluster": { "Ref": "Cluster" },
"DesiredCount": { "Ref": "InstanceCount" },
"LoadBalancers": [
{
"TargetGroupArn": { "Ref": "HTTPSTargetGroup" },
"ContainerName": "nginx",
"ContainerPort": "9002"
}
],
"Role": { "Ref": "ServiceRole" },
"TaskDefinition": { "Ref": "TaskDefinition" }
}
}
A CloudFormation solution would be ideal, but an API solution would also be of interest.
I could create a second Service
for HTTP, with a separate load balancer and container instances, but that would be neither simple nor economical.