I want to use Session Manager, a capability of AWS Systems Manager, to create port forwarding.
Resolution
Create a port forwarding session for port 80, then load your website from the local host address on your local machine. It isn't necessary to open inbound port 80 on the managed instance in a security group or a network access control list (network ACL).
Prerequisites
Complete the following steps:
-
Confirm that Systems Manager is managing your Amazon Elastic Compute Cloud (Amazon EC2) instance. For more information, see Managing EC2 instances with Systems Manager and Manually installing and uninstalling SSM Agent on EC2 instances for Linux.
-
Install the Session Manager plugin for the AWS Command Line Interface (AWS CLI).
Note: If you receive errors when you run AWS CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
-
Run the following commands to verify that the port in the target instance is in listening mode:
Linux OS
netstat -plant
Windows OS
netstat -nb
Create a port forwarding session
Run the following commands. Be sure to replace the example values with your required values:
Linux or macOS
# aws ssm start-session \
--target example-EC2-instance-ID \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["80"], "localPortNumber":["example-local-port"]}'
Windows
> aws ssm start-session
--target "example-EC2-instance-ID" --document-name AWS-StartPortForwardingSession --parameters "portNumber"=["80"],"localPortNumber"=["example-local-port"]
Open the browser on your local machine, and then load http://localhost:example-local-port to view the web server content from your Amazon EC2 instance.