Communicating between containers within the same container service in AWS LightSail

0

I'm a beginner developer working on a deploying a full-stack project to lightsail container services and running into issues with deployment.

Everything works fine locally on my docker desktop, my frontend is a react app in a nginx web server exposed on port 80. My backend is a nodejs server exposed on port 5000.

The frontend image expects an env variable with the server url to make api requests (I'm using runtime env variables by the way, I got that working fine).

The backend image expects an env variable with the frontend url to allow cors.

Locally, I'm passing in the env variables as: FRONTEND_URL=http://localhost:8080 and BACKEND_URL=http://localhost:5000

When I deploy to lightsail and I pass in the env variables, I'm following the steps listed in the documentation here for communication between containers within the same container service. https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services-deployments#communication-between-containers

I've tried passing in as the FRONTEND_URL env variable: service://localhost:80, service://localhost, http://localhost:80, http://localhost

I've tried passing in as the BACKEND_URL env variable: service://localhost:5000, http://localhost:5000, I also tried using the private domain of my lightsail container service (e.g. container-react1.service.local:5000) .

I'm selecting the frontend container for the public endpoint. I'm able to deploy the app and access the app as normal in all cases, but when I try to access the api route I get an error: net::ERR_CONNECTION_REFUSED.

Any thoughts on getting around this?

asked a year ago260 views
1 Answer
0

Hi! I've seen that you were able to fix your issues and serve both web app and api with same container service.

I have a web app serving publicly in a port and access an API both in the same Container Service. I am trying to use SERVICE_CON service://localhost as suggested by documentation but it is not working. Any clue? I can see both logs for containers look good, both on steady state serving on both ports.

I use that as the VITE_BASE_URL in the client app to access the API endpoints but the browser complains saying:

service://localhost:3001/api/myassessment ----> URL scheme "service" is not supported.

If anyone has any idea how to fix this, I would appreciate your comments. I also tried using **nginx **to proxy pass the access to API but using the private domain for my container service does not work as expected.

Thanks for your help!

answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions