How to Enable Communication Between Two Containers in the Same ECS Task?

0
0
Asked By TechieTurtle77 On

I'm trying to set up intercommunication between two containers running in the same ECS task. I have a Terraform script that creates a cluster and launches it with a target group backed by EC2 instances. My task definition includes a Node.js app and a PostgreSQL database, but I can't seem to get the Node app to connect to PostgreSQL.

I've been using Sequelize in the Node.js app, and I've verified that the user, password, and database names are correct. I've tried using the container name 'Postgres' and 'localhost' as the host, but I'm getting an error stating that the Postgres host is not found, and when I use localhost, I get a connection refused error.

Does anyone have any insights on how to achieve intercommunication in ECS with this setup?

2 Answers

Answered By NetworkWhiz On

What networking mode are you using for your task? This could affect connectivity between your containers.

TechieTurtle77 -

I'm using awsvpc.

Answered By CodeMaster42 On

You might want to check this setup I found: https://github.com/AvinashDalvi89/aws-fargate-examples/tree/main/simple-php-website. I had a similar issue when using PHP and MySQL. A couple of things to try:
- Stick to 'localhost:' in Sequelize.
- Make sure your Postgres is configured to listen on 0.0.0.0.
- Use 'dependsOn' in your task definition to ensure the Node app waits until Postgres is healthy before trying to connect.

CuriousCoder99 -

Hmm. I tried this and no dice.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.