Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I alias containers running a UDP service on ECS?

I'm attempting to run logstash in a container against ECS, which will listen for log messages over UDP.

I want my apps to be able to send messages to e.g. logging.mydomain.com without needing to know the underlying IP(s) which may change.

Normally I would CNAME an ELB, but ELB does not support UDP. Do I need to do some kind of service discovery here or is there something simpler I can do?

like image 495
Dan Avatar asked May 31 '17 16:05

Dan


People also ask

Can an ECS Task have multiple containers?

You can use an Amazon ECS task definition to specify multiple containers. All the containers that you specify are deployed along the same compute capacity. Don't use this feature to add multiple application containers to the same task definition because this prevents copies of each application scaling separately.

Can ECS host Docker containers?

Amazon ECS is a highly scalable, high performance container management service that supports Docker containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances.

How containers communicate with each other in ECS?

In the same ECS service, containers can communicate with each other by localhost. In the diffrent ECS service, containers can communicate with each other by service discovery.


1 Answers

I would recommend using Amazon Route 53 DNS round robin to solve this problem.

The pieces are:

  • A Lambda function attached to the Cloudwatch Events stream for your logstash service in ECS. This lambda function will be invoked whenever there is a task state change, and so it runs when a new logstash task is started or stopped and updates the Route 53 record
  • When your application resolves the dns record it will be given one of the IP addresses round robin style and communicate directly with the instance hosting the logstash container, using its IP.
  • Your ECS service will need to have a statically assigned host port rather than a dynamic port.

There is a reference architecture that described this in more detail, and has sample code for you: https://aws.amazon.com/blogs/compute/service-discovery-for-amazon-ecs-using-dns/

like image 190
nathanpeck Avatar answered Sep 28 '22 00:09

nathanpeck