Jordan
Jordan

Reputation: 580

AWS ECS service with multiple task need load balancer

I have the following stack (deployed by CloudFormation):

  1. SQS queue that trigger a lambda function
  2. The lambda function is calling an ECS service (by http post request - which is an express.js server)

I am going to create an autoscaling configuration for the ECS service to scale up and down based on SQS metric.

If there will be multiple tasks in the service (means there were a lot of SQS messages) how will the service manage the calls to the tasks? will I need to add a load balancer for the service? or the service know how to balance it between the tasks without load balancer?

Upvotes: 1

Views: 757

Answers (1)

Marcin
Marcin

Reputation: 238209

I think there are two ways to deal with this.

  1. Use load balancer as you pointed out. It can be internal load balancer. In this case, lambda will be associated with a VPC and will call the balancer's private dns.

  2. Use ECS service discovery. This can also server as sort-of load balancer, though not as feature reach as regular balancer. The reason is that the private url associated with the service will return multiple IPs of its tasks, and the distribution of incoming requests is based on DNS cache timeouts. After each timeout, the IPs will be in different order. For this lambda would also be in a vpc and use private url associated with the ECS service to invoke your service.

Upvotes: 2

Related Questions