Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service discovery on aws ECS with Application Load Balancer

I would like to ask you if you have an microservice architecture (based on Spring Boot) involving Amazon Elastic Container Service (ECS) with Application Load Balancer(ALB), service discovery is performed automatically by the platform, or do you need a special mechanism (such as Eureka or Consul)?

From the documentation (ECS and ALB) is not clear you have this feature provided.

like image 326
florins Avatar asked Oct 18 '17 10:10

florins


Video Answer


2 Answers

I have talked this with the Amazon support team and they respond the following: "...using Service Discovery on AWS ECS[..] just with ALBs.

So, there could be three options here: 1) Using ALB/ELB as service endpoints (Target groups for ALBs, separate ELBs if using ELBs)

2) Using Route53 and DNS for Service Discovery

3) Using a 3rd Party product like Consul.io in combination with Nginx.

Let me speak about each of these options.

Using ALBs/ELBs

For this option the idea is to use the ELBs or ALB Target groups in front of each service. We define an Amazon CloudWatch Events filter which listens to all ECS service creation messages from AWS CloudTrail and triggers an Amazon Lambda function. This function identifies which Elastic Load Balancing load balancer (or an ALB Target group) is used by the new service and inserts a DNS resource record (CNAME) pointing to it, using Amazon Route 53. The Lambda function also handles service deletion to make sure that the DNS records reflect the current state of applications running in your cluster.

The down side here is that it can incur higher costs if you are using ELBs - as you need an ELB for each service. And it might not be the simplest solution out there. If you wish to read more on this you can do so here[1]

Using Route53

This approach involves the use of Route53 and running a simple agent[2] on your ECS container instances. As your containers stop/start the agent will update the Route53 DNS records. It creates a SRV record. Likewise it will delete said records once the container is stopped.

Another part of this method is a Lambda function that performs health checks on ECS container instances - and removes them from R53 in case of a failure.

You can read up more on this method, on our blog post here[3].

Using a 3rd Party tool like Consul.io Using tools like Consul.io on ECS, will work - but is not supported by AWS. So you are free to use it, but we - unfortunately - do not offer support for it.

So, in conclusion - there are a few ways of implementing service discovery on AWS ECS - the two ways I showed here that use AWS resources, and of course the way of using 3rd party applications. "

like image 134
florins Avatar answered Nov 15 '22 08:11

florins


you dont have an out-of-the-box solution in AWS, although it is possible with some effort as described in https://aws.amazon.com/es/blogs/compute/service-discovery-an-amazon-ecs-reference-architecture/

You may also install Zuul + Ribbon + Eureka or Nginx + Consul and use ALB to distribute traffic among Zuul or Nginx

like image 40
jmhostalet Avatar answered Nov 15 '22 10:11

jmhostalet