Launch an EC2 instance in the same subnet as the RDS database or Redis cluster.
Make sure that the EC2 instance is an SSM managed instance and its SSM agent ping status is Online. If you launched the instance in private subnet, create endpoints required for connectivity with Session Manager.
Run the following AWS CLI command on your local machine to open a remote port forwarding session:
Note: Replace the following variables with your variables:
"i-0822xxxxxxx4309b" with your EC2 instance.
"example-group.0123abcd.0001.aps1.cache.amazonaws.com" with your Amazon RDS or Redis cluster node endpoint.
"3306" with the remote host port number that you're connecting to.
"6379" with your client localhost port number.
Example output macOS or Linux:
Starting session with SessionId: XXXXX49c94e084f10c
Port 6379 opened for sessionId XXXXX49c94e084f10c.
Waiting for connections...
Connection accepted for session [XXXXX49c94e084f10c]
Example output Windows:
alice@local-host ~ % redis-cli -c -h localhost -p 6379
localhost:6379> set a "Hello"
OK
localhost:6379> get a
"Hello"
localhost:6379> quit
alice@local-host ~ %
Press Ctrl-C to close the remote port forwarding session.
Example macOS or Linux:
^CTerminate signal received, exiting.
Exiting session with sessionId: XXXXX49c94e084f10c.
alice@local-host ~ %