<p>The goal can be achieved via several solutions. We can use service with <strong>awsvpc</strong> as network mode, so your service can get a real "<strong>A</strong>" <strong>DNS</strong> record and ENI interface, you must pay attention with this solution, ec2 instances has a limited number of ENI that can be attached, for a micro or small I think max 3.</p>

<p>Other solution more flexible is to use an internal <strong>NLB</strong> or custom proxy like <strong>HAproxy</strong> as <strong>ambassador</strong>, you run the proxy as service with awsvpc so he can get his "<strong>A</strong>" <strong>DNS</strong> record eg <strong>proxy.prod</strong>, all other services like Redis, Mongo, Elasticsearch ... can be configured as service with bridge networking mode so they will get an <strong>SRV</strong> record if configured with service discovery.</p>

<p>Finally you have to configure your proxy to redirect all traffic to desired service using port forwarding. <strong>HAproxy</strong> can resolve "<strong>SRV</strong>" records so you don't have to deal with that <strong>HAproxy</strong> will do it for you, you must just configure your app to use <strong>proxy.prod</strong> + port, for each service so:</p>

<ul>
<li><em>Redis</em> <strong>proxy.prod:6379</strong></li>
<li><em>Mongo</em> <strong>proxy.prod:27017</strong></li>
<li>And so on...</li>
</ul>

<p>Using this technique you can do a lot of amazing things, no matter where your proxy can lives, it can run as container in the same node with your apps or on a <strong>Fargate</strong> or in another node ...</p>

CC BY-SA 4.0
2019-12-28T16:20:21.073Z
2019-12-30T13:53:56.103Z
2019-12-30T13:53:56.103Z
Mohamed
<p>I'm trying to use amazon service discovery to register a Redis server in order to be reachable by other <strong>ECS</strong> services in the same cluster.</p>

<p>I'm using <strong>EC2</strong> to deploy my services not Fargate, so service discovery create a simple <strong>SRV</strong> DNS record, that's mean my others services must request <strong>R53</strong> service to get a real "<strong>A</strong>" record to have access to Redis service.</p>

<p>My question for DevOps/AWS engineer is: what's the correct way to do so? A request to <strong>R53</strong> each time absolutely not a good idea.</p>

<p>My solution is in comments.</p>

CC BY-SA 4.0
2019-12-25T11:45:25.703Z
Thank you for posting a question. Could you modify the question so that it contains the attempts you have done in order to solve the issue?
030
CC BY-SA 4.0
2019-12-27T15:54:12.170Z
Could you post an answer? Then people can upvote it.
030
CC BY-SA 4.0
2019-12-28T16:06:45.587Z
Yes, I tried to answer but as the question was marked as closed it wasn't possible
Mohamed
<amazon-ec2><amazon-ecs><fargate>
How to use ecs service dicovery
Mohamed
# How to use ecs service dicovery

(Asked by: username_0 on 2019-03-04)

I'm trying to use amazon service discovery to register a Redis server in order to be reachable by other **ECS** services in the same cluster.

I'm using **EC2** to deploy my services not Fargate, so service discovery create a simple **SRV** DNS record, that's mean my others services must request **R53** service to get a real "**A**" record to have access to Redis service.

My question for DevOps/AWS engineer is: what's the correct way to do so? A request to **R53** each time absolutely not a good idea.

My solution is in comments.

**Tags:** amazon-ec2, amazon-ecs, fargate

> **Comments:**
> **username_1**: Thank you for posting a question. Could you modify the question so that it contains the attempts you have done in order to solve the issue?  
> **username_1**: Could you post an answer? Then people can upvote it.  
> **username_0**: Yes, I tried to answer but as the question was marked as closed it wasn't possible  

---

## 1 answers

### Answer by username_0 on 2019-12-28. Score: 2 | Accepted answer

The goal can be achieved via several solutions. We can use service with **awsvpc** as network mode, so your service can get a real "**A**" **DNS** record and ENI interface, you must pay attention with this solution, ec2 instances has a limited number of ENI that can be attached, for a micro or small I think max 3.

Other solution more flexible is to use an internal **NLB** or custom proxy like **HAproxy** as **ambassador**, you run the proxy as service with awsvpc so he can get his "**A**" **DNS** record eg **proxy.prod**, all other services like Redis, Mongo, Elasticsearch ... can be configured as service with bridge networking mode so they will get an **SRV** record if configured with service discovery.

Finally you have to configure your proxy to redirect all traffic to desired service using port forwarding. **HAproxy** can resolve "**SRV**" records so you don't have to deal with that **HAproxy** will do it for you, you must just configure your app to use **proxy.prod** + port, for each service so:

* *Redis* **proxy.prod:6379**
* *Mongo* **proxy.prod:27017**
* And so on...

Using this technique you can do a lot of amazing things, no matter where your proxy can lives, it can run as container in the same node with your apps or on a **Fargate** or in another node ...


---

