Session Manager Port Forwarding feature allows you to tunnel data from remote port on instance to a local port on client machine. This enables web redirection for user without opening inbound ports. You can use this feature using AWS CLI which requires you to install session-manager-plugin on client machine. It uses public SSM document AWS-StartPortForwardingSession that allows users to provide local and remote port numbers to enable port forwarding.
Review SSM Document
Install Apache HTTP Server on EC2 instance
Under Instances & Nodes in the AWS Systems Manager navigation menu, browse to the Session Manager console and start a session to linux instance session-manager-linux-stage.
Type command below
sudo yum -y install httpd; sudo systemctl enable httpd; sudo systemctl start httpd
You should see an output as shown below.
Verify apache http server(httpd) is running on port 80 by running command
sudo netstat -atnp | grep -i httpd
You should see an output as shown below.
Start Port Redirection
Browse to the AWS Cloud9 IDE and type below command in the console after replacing with appropriate instance ID to start a session to session-manager-linux-stage instance.
aws ssm start-session --target <instance-id> --document-name AWS-StartPortForwardingSession --parameters "localPortNumber=8080"
You should see a message indicating port 8080 has been opened for this session.
Within Cloud9 to preview a web page, select Preview from the menu option and Preview Running Application as shown below. You should be able to access Apache http server home page which is running on port 443 on remote instance session-manager-linux-stage.
Press Control+C on terminal to terminate the session.
This video has no audio