0

I have a little architecture with two services running on a EC2 cluster of AWS ECS, they're healthy and I can access them via browser through two ALBs, pointing to frontend and backend respectively. My frontend container can configure its backend base url so I want to connect it to the backend with a proper namespace with Route 53 Service Discovery (and not using ALB dns name).

My problem is I configured the tasks with awspvc mode and pointed them to the unique port I want to expose, but the EC2 instances (and the containers when I access via ssh) can't reach the short namespace, I have to add the name of the container and its port, but I can't abstract them (I think they're the original containers because the names does not match in pictures 2 and 3 but they're still accesable). When I used Fargate I could reach the containers only providing the service name and namespace, but now I can't with EC2.

I'll attach some pictures I believe they're useful (red is the same name for all texts):

service discovery of backend

route 53 records

active containers

KratoSeba
  • 9
  • 2
  • Is your frontend making calls to the backend via HTTP calls in the browser? Or via backend server-to-server communications? Can you show the code that is making the calls to the backend? The code doesn't appear to be using SRV records correctly. – Mark B Jul 25 '22 at 16:19
  • Hi, I will test that lately, from now I'm accesing to the EC2 instances via ssh and making curl requests. Currently it works with "curl c9ab79c2d9084daa99389e217c2d93e7.api.[REDACTED]-admin:5000" but not working with "curl api.[REDACTED]-admin" – KratoSeba Jul 25 '22 at 16:22
  • You didn't really answer any of my questions. I'm trying to point out that if your end goal is to make HTTP requests to the backend via front-end code running in the browser, then service discovery is not going to work for you at all. – Mark B Jul 25 '22 at 16:24
  • Your `curl` command isn't working because `curl` doesn't currently support SRV records. – Mark B Jul 25 '22 at 16:27
  • Oh well, sorry. The frontend makes calls to the backend via server-to-server, it is a React app and it's fetching data with axios, none of api calls are done in browser. – KratoSeba Jul 25 '22 at 16:37
  • A React app fetching data via Axios runs in the web browser, not the server... Those calls are all done in browser. React is a JavaScript **browser** framework. Your front-end server is just serving up raw JavaScript files to the browser. The Browser actually runs the code. – Mark B Jul 25 '22 at 16:44
  • As I said, that will be tested lately, it is running behind an nginx and other stuff and that is not the problem of my question (I haven't joined the webpage yet). I'm actually asking about the fact the containers are discoverable if I provide the name of the container but I just want to provide the service name and namespace, so I am doing something bad in that configuration. Btw, thank you for the additional explanation :o – KratoSeba Jul 25 '22 at 17:07

0 Answers0