AWS Beanstalk Django Cannot Connect to RDS Instance Because Wrong Private IP Resolved from RDS Endpoint

My setup:

  1. AWS RDS MySQL Instance located in a custom VPC (Private Subnet)
  2. AWS Beanstalk Django app located in the same custom VPC (Public Subnet)
  3. Beanstalk EC2 Private IP: 10.0.2.37
  4. RDS Endpoint: stockpeektestdbcachekafka-trading-db.cxapiv8ipcaj.ap-southeast-1.rds.amazonaws.com
  5. RDS Private IP after using telnet to the RDS Endpoint inside Beanstalk EC2: 10.0.4.163

The problem:

  1. I keep getting DB connection refused error with my Django app
  2. Looking closer at the error msg: it is because the RDS endpoint URL is resolved to the EC2 Private IP instead Error Image Link
  3. This is still happening although I have set DB HOST in settings.py to be the RDS Endpoint

How to fix this endpoint resolve error? Thanks!`

Back to Top