Search code examples
amazon-ec2amazon-elbamazon-ecs

Autoscaled web service running on EC2: use Auto Scaling Launch Config with custom AMI or use ECS?


It seems to me that there are two alternate ways of having an autoscaled web service running on EC2 instances behind an ELB:

1) create an Auto Scaling Launch Config that specifies the image id of my custom AMI (and the instance type to use). Then, when the Auto Scaling trigger is triggered, it will simply spin up new EC2 instances using that AMI.

2) Use ELB and ECS instead as ECS seems to have its own Auto Scaling feature.

In what circumstances is it better to use ECS?


Solution

  • The two options are not mutually exclusive. To answer your last question first, you use ECS when you run containerized applications. You can scale these applications using the Service AutoScaling service in ECS. This will help you bring up additional containers when you're running short of resources to attend incoming requests.

    This is different from scaling EC2 instances with a Launch Configuration. You'll need additional instances when you run out of resources in order to spin up new containers in your ECS cluster. By the way, you should always use a Launch Configuration in order bring new EC2 instances within an AutoScaling group bound to your ECS cluster, since it makes everything a lot easier. See for example this tutorial.

    As for the ELB, in ECS you actually are better off using ALB. In containerized applications, you need to map their exposed ports to random ports in the host machine. This makes the registration with the load balance a lot more complicated. However, ALB is integrated with ECS so that, whenever you launch a new task, the ECS Service running the task requests a registration of the task as a target for the ALB (see this link for a more detailed explanation). It takes care of everything on your behalf.