Attaching an Application Load Balancer to an ECS cluster
Load balancers are a must-have for any containerized application that wants to run on a cluster. You can easily add a load balancer and apply it to the specific image/port that you want exposed. This makes it easy to repeatedly deploy new services while always making them accessible via the load balancer, thus reducing down time.
1. Add a load balancer resource
resources: - name: app_lb type: loadBalancer pointer: role: role_for_ecs_lb sourceName: arn:aws:elasticloadbalancing:us-east-1:679404489841:targetgroup/ecs-deploy-alb-tgtgrp/394643319fd6a729 method: application
pointerattribute in this resource expects three values to be specified.
rolevalue is set to the name of an AWS IAM role that has the appropriate policy and trust relationship for service load balancing. You can find that information in the AmazonECS service load balancing documentation.
sourceNamefield is set to the ARN of the target group that was created alongside your ALB. Make sure this is the ARN of the target group and not the ARN of the load balancer itself.
methodvalue is always set to
2. Update your deploy job
deployjob where you want to attach the load balancer. In our example for the single container application, this job is named
applyTosection in the
applyTosection expects the following values to be set:
manifestshould be the name of the manifest job that needs to be load balanced
imageis the resource name of the specific image within that manifest
portis the container port of that container that is being exposed.
In our example for the single container application, the yml snippet would look like this:
jobs: - name: app_deploy_job type: deploy steps: - IN: app_service_def - IN: op_cluster - IN: app_replicas - IN: app_lb # this should match name of the loadBalancer resource applyTo: - manifest: app_service_def image: app_image port: 80
Your load balancer will be attached when the deploy job runs next. To trigger it manually, follow instructions here.
Source code: devops-recipes/deploy-ecs-elb
Ask questions on Chat
Feel free to engage us on Chat if you have any questions about this document. Simply click on the Chat icon on the bottom right corner of this page and someone from our customer success team will get in touch with you.
Improve this page
We really appreciate your help in improving our documentation. If you find any problems with this page, please do not hesitate to reach out at email@example.com or open a support issue. You can also send us a pull request to the docs repository.