Cannot connect docker container on ECS Fargate to RDS db instance


I've been pulling my hair out trying to connect my docker container on ECS Fargate to my RDS instance without success for the past 3 hours and I don't know why it's not working.

I have a ruby docker image with db config like this:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  <<: *default
  host: <%= ENV['DATABASE_URL'] %>
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>
  database: my_project_db


which is the RDS endpoint URL. My database identifier name is myprojectdbinstance and initial database name is my_project_db.

When I run my ECS task I get an error:

ActiveRecord::NoDatabaseError: We could not find your database: Which can be found in the database configuration file located at config/database.yml

PG::ConnectionBad: could not translate host name "" to address: Name does not resolve

My ECS and RDS db are in the same VPC. The ECS Task is in projects-alb-sg security group, my RDS accepts inbound traffic from projects-alb-sg security group. My VPC supports DNS resolution and DNS hostnames and RDS database is publicly available. I have created DB subnet group with the same subnets where my ECS task is located. I have already tried all possible settings and it doesn't work.

My VPC has DNS resolution enabled.

What am I missing?

3 Answers

¿Maybe you need a public IP to resolve "" DNS?

answered a year ago
  • I do set Public IP on the task


Fagrate 1.3 or 1.4 ?

With Fargate 1.4, did you create a Task Execution Role ?

Take a look at this tutorial.

Did you create the environment variables in the task definition ?

profile pictureAWS
answered a year ago
  • Fargate is latest, I do have the default execution role ecsTaskExecutionRole. I do have the environment variables in the task definition. DATABASE_URL, DATABASE_USERNAME and DATABASE_PASSWORD, which point to my RDS DB endpoint, username and password.


It turned out that the right DATABASE_URL should be postgres://postgres@mydbendpoint/my_project_db and it worked.

answered a year 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