Ongoing service disruptions
For the most recent update on ongoing service disruptions affecting the AWS Middle East (UAE) Region (ME-CENTRAL-1), refer to the AWS Health Dashboard. For information on AWS Service migration, see How do I migrate my services to another region?
我想使用 Session Manager (AWS Systems Manager 的一項功能) 來建立連接埠轉送。
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
若要使用 Session Manager 來建立連接埠轉送,請完成下列步驟:
確認 Systems Manager 管理您的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。如需詳細資訊,請參閱使用 Systems Manager 管理 EC2 執行個體和在 Linux 的 EC2 執行個體上手動安裝和解除安裝 AWS Systems Manager Agent。
安裝適用於 AWS CLI 的 Session Manager 外掛程式。
若要確認目標 EC2 執行個體中的連接埠是否處於接聽模式,請執行下列命令: Linux:
netstat -plant
macOS:
lsof -iTCP -sTCP:LISTEN -P -n
Windows:
netstat -nb
設定 AWS Identity and Access Management (IAM) 政策,允許使用者透過 Systems Manager 使用連接埠轉送工作階段。下列 IAM 政策範例允許在 AWS 帳戶中的所有 EC2 執行個體上進行連接埠轉送:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": "ssm:StartSession", "Resource": [ "arn:aws:ec2:*:example-account-id:instance/*", "arn:aws:ssm:*::document/AWS-StartPortForwardingSession" ] } ] }
**注意:**將 example-account-id 替換為您的帳戶 ID:
根據您的作業系統執行命令。 Linux 或 macOS:
# aws ssm start-session \ --target example-EC2-instance-ID \ --document-name AWS-StartPortForwardingSession \ --parameters '{"portNumber":["80"], "localPortNumber":["example-local-port"]}'
**注意:**將 example-EC2-instance-ID 替換為您的 EC2 執行個體 ID,將 example-local-port 替換為您的本機連接埠。 Windows:
# aws ssm start-session --target "example-EC2-instance-ID" --document-name AWS-StartPortForwardingSession --parameters "portNumber"=["80"],"localPortNumber"=["example-local-port"]
**注意:**將 example-EC2-instance-ID 替換為您的 EC2 執行個體 ID,將 example-local-port 替換為您的本機連接埠。
若要從您的執行個體查看 Web 伺服器內容,請在本機的瀏覽器中載入 http://localhost:example-local-port。 **注意:**無需在安全群組或網路存取控制清單中開啟受管 EC2 執行個體上的傳入連接埠 80。