Attaching a Classic 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 loadBalancer resource
resources: - name: deploy_ecs_lb # name of loadBalancer resource type: loadBalancer pointer: role: role_for_ecs_lb sourceName: deploy_ecs_elb
pointerattribute in this resource expects two values:
roleis 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 name of your load balancer on AWS.
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: deploy_ecs_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.