awslabs / fargatecli

CLI for AWS Fargate
Apache License 2.0
893 stars 114 forks source link

Communication between services, what hostname? #43

Closed djheru closed 6 years ago

djheru commented 6 years ago

Thanks for making this great tool. I have a question I'm hoping will have a simple answer. I'm experimenting with this tool trying to set up a number of HTTP REST APIs. I am able to make requests from a client through the load balancer just fine, using the DNS name from the load balancer, but I'm not sure how I can make requests between services.

I have services (servicea, serviceb) and their containers are exposing ports 8001 and 8002. I would like servicea to be able to make HTTP requests to serviceb without having to go through the load balancer. I've tried using e.g. http://localhost:8002 and http://serviceb:8002 and neither one of those work (ENOTFOUND) is there any way to set it up so that the services can reach each other over HTTP using information that is available at the time the containers are built?

Thanks for your time!

jpignata commented 6 years ago

Hey! Within the same task, all containers share the same network namespace, so it should be accessible via 127.0.0.1:8002. If it's another task, today you'll have to either use an ELB or roll your own service discovery using either the ECS event stream and route 53 or a third party distributed config system like Consul. I'll integrate with ECS' service discovery feature when Fargate tasks are supported by it to allow a container to reach a pool of another task via serviceb:8002.

Does that help?

djheru commented 6 years ago

Thanks for the reply! I ended up just sending requests between different services through the ELB. I'm setting the ELB host name as an env var and passing that to fargate when I create the service.

Thanks again for the great tool.

jritsema commented 6 years ago

Looks like this is very timely!

https://aws.amazon.com/about-aws/whats-new/2018/03/aws-fargate-platform-version-1-1/