Reading time : 1 minute
Its been long time since i wrote any blogs. I have been tied up with lot of other stuffs. I had decided to continue blogging periodically.
What is Eureka
Eureka is the service discovery engine, which is used in the netflix microservice stack. Netflix stack is based on java and it is now integrated with spring cloud ecosystem. The service discovery will act like a dns server, where the location (ip and port) for each microservice is stored. If any microservice needs to communicate to another service, it will ask the service discovery ie eureka for the location of the service.
Problem with AWS ECS
Eureka works fine if integrated in any local environment. But when we deploy it to AWS ECS, which is a docker based container service we will face some problems. Mainly it is due to the IP resolution. The IP which is registered by any service in eureka will be the internal local container IP. This will create problems when eureka is present in a ec2 instance and service in another ec2 instance.
The solution is to get the instance ip of the ec2 where the container is running and the exported port of the container so that it is possible to connect to the service in different ec2 instances.
In order to get the public ip of the ec2, we just need to call a url hosted by AWS “http://169.254.169.254/latest/meta-data/local-ipv4” which returns the public ip of the calling ec2 instance.
For getting the exposed port, we will use a spotify’s docker library, which gives the container details.
Add the below dependencies to the build.gradle
Then you need to create the below configuration class.
Now go and check the eureka’s dashboard. You will see the external IP and port for the microservice.