Interview Prep/AWS/RDS, Aurora and DynamoDB

The app cannot connect to RDS: `psql: error: connection to server at "mydb.abc.us-east-1.rds.amazonaws.com" (10.0.3.12), port 5432 failed: Connection timed out`.

BeginnerTroubleshootingRDS, Aurora and DynamoDB
Answer

Likely causes → A timeout means the packets are dropped. The DB SG does not allow 5432 from the app SG, a NACL blocks it, or the client is outside the VPC (for example, a laptop) while the DB is not publicly accessible (which is how it should be).

Diagnose →

aws rds describe-db-instances --db-instance-identifier mydb \
  --query 'DBInstances[].[Endpoint.Address,Endpoint.Port,PubliclyAccessible,VpcSecurityGroups,DBSubnetGroup.Subnets[].SubnetIdentifier]'
nc -zv mydb.abc.us-east-1.rds.amazonaws.com 5432
aws ec2 describe-security-groups --group-ids <db-sg> --query 'SecurityGroups[].IpPermissions'

Fix →

  1. Allow 5432 on the DB SG from the app SG
  2. From a laptop, use SSM port forwarding through a bastion: aws ssm start-session --target i-0abc --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host=mydb...,portNumber=5432,localPortNumber=5432

Prevent → Keep databases in private subnets and grant access by SG reference only.

aws All AWS questions Roadmap: AWS core services

More on RDS, Aurora and DynamoDB