I am having trouble accessing AWS RDS instance in a private subnet using session manager through ec2 instance (Ubuntu).
Port forwarding using AWS Session manager -
aws ssm start-session --target $INSTANCE_ID \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":[3307],"localPortNumber":["8000"]}' \
--profile=production \
--region=us-east-1`
Now local port 8000 successfully forwarded to port 3307 of EC2.
lsof -nP +c 15 | grep LISTEN
session-manager 59744 xrage 12u IPv4 0xa6c821d0a800e9a1 0t0 TCP 127.0.0.1:8000 (LISTEN)
EC2 instance has an iptable rule that forward all traffic on port 3307 to rds host at port 3306 (MYSQL PORT).
sudo iptables -t nat -A OUTPUT -o lo -d 127.0.0.1 -p tcp --dport 3307 -j DNAT --to-destination <rds_private_ip>:3306
This allowed me to access remote host on the desired port from ec2, But still, the remote host is not accessible locally on port 8000.
Network details on the local machine -
- Not using any proxy
- Firewall disabled on mac
So it's clear that SSM setup is working but something else is blocking this traffic, Need some help here.