Sunday, 23 August 2026

Connect AWS RDS using port forward

  1. find end points:
    1. AWS RDS mysql database endpoint: leo-mysql.abcde12222.us-east-1.rds.amazonaws.com
    2. AWS RDS proxy end point: ddd-accesss.proxy-abcde12222.us-east-1.rds.amazonaws.com
  2. set a jump box
    Host mm-myjump
        HostName 54.70.111.222
        User ec2-user
        IdentityFile ~/.ssh/NOC.pem
        ServerAliveInterval 60
        ServerAliveCountMax 3
        LocalForward 3333 ddd-accesss.proxy-abcde12222.us-east-1.rds.amazonaws.com:3306
        LocalForward 3311 leo-mysql.abcde12222.us-east-1.rds.amazonaws.com:3306
  3. check whether a TCP port is reachable.
    ssh mm-myjump
    nc -zv leo-mysql.abcde12222.us-east-1.rds.amazonaws.com 3306
    nc -zv ddd-accesss.proxy-abcde12222.us-east-1.rds.amazonaws.com  3306

    Test result: see connected and it is good.

  4. find ips of proxy
    getent hosts ddd-accesss.proxy-abcde12222.us-east-1.rds.amazonaws.com
    10.32.111.222   vpce-0d550c1ebeb3a6159-jq0x2yyd.vpce-svc-0a3de4cabd09a2ae4.us-east-1.vpce.amazonaws.com ddd-accesss.proxy-abcde12222.us-east-1.rds.amazonaws.com
    10.32.888.999   vpce-0d550c1ebeb3a6159-jq0x2yyd.vpce-svc-0a3de4cabd09a2ae4.us-east-1.vpce.amazonaws.com ddd-accesss.proxy-abcde12222.us-east-1.rds.amazonaws.com
  5. find ip of jump box
    10-16-222-888
  6. set allow host for the user and test
    # connect to data base end point directly, only need 10.16.%.%
    
    mysql --host='127.0.0.1' -P 3311  --user=tester --password='test12233*' -A revenuewireDW
    SELECT USER(), CURRENT_USER();
    
    # connect to data base proxy, only need 10.32.%.% (becuase db think the host is from proxy. 
    #Also will not match exactly to end point ip. Therefore, use wild cat here). Also need to set
    #user name and password in secret manage for this option.
    
    mysql --host='127.0.0.1' -P 3333  --user=tester --password='test12233*' -A revenuewireDW
    SELECT USER(), CURRENT_USER();