本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 AWS CloudShell 來使用 AWS App Runner
AWS CloudShell 是以瀏覽器為基礎的預先驗證 Shell,您可以直接從 啟動 AWS Management Console。您可以使用您偏好的 shell (Bash、PowerShell 或 Z shell AWS App Runner) 對 AWS 服務 (包括) 執行 AWS CLI 命令。另外,您無需下載或安裝命令列工具即可執行此操作。
您AWS CloudShell 從 啟動 AWS Management Console ,而您用來登入 主控台的 AWS 登入資料會自動在新的 shell 工作階段中使用。此預先驗證 AWS CloudShell 使用者可讓您在使用 AWS CLI 版本 2 與 App Runner 等 AWS 服務互動時略過設定登入資料 (預先安裝在 shell 的運算環境)。
取得 的 IAM 許可 AWS CloudShell
AWS Identity and Access Management管理員可以使用 提供的存取管理資源,將許可授予 IAM 使用者,讓他們可以存取 AWS CloudShell 和使用環境的功能。
管理員授予使用者存取權的最快方式是透過 AWS 受管政策。AWS 受管政策是由 AWS建立並管理的獨立政策。下列適用於 CloudShell 的 AWS 受管政策可以連接到 IAM 身分:
-
AWSCloudShellFullAccess
:授予許可,以 AWS CloudShell 完整存取所有功能。
如果您想要限制 IAM 使用者可執行的動作範圍 AWS CloudShell,您可以建立使用 AWSCloudShellFullAccess
受管政策做為範本的自訂政策。如需限制 CloudShell 中使用者可用的動作的詳細資訊,請參閱AWS CloudShell 《 使用者指南》中的使用 IAM 政策管理 AWS CloudShell 存取和用量。
注意
您的 IAM 身分也需要 政策,授予對 App Runner 呼叫的許可。如需詳細資訊,請參閱App Runner 如何與 IAM 搭配使用。
使用 與 App Runner 互動 AWS CloudShell
AWS CloudShell 從 啟動後 AWS Management Console,您可以立即開始使用命令列界面與 App Runner 互動。
在下列範例中,您會使用 CloudShell AWS CLI 中的 擷取其中一個 App Runner 服務的相關資訊。
注意
使用 AWS CLI 時 AWS CloudShell,您不需要下載或安裝任何其他資源。此外,因為您已經在 Shell 中驗證身分,因此無需設定憑證即可呼叫。
範例 使用 擷取 App Runner 服務資訊 AWS CloudShell
-
從 中 AWS Management Console,您可以選擇導覽列上可用的下列選項來啟動 CloudShell:
-
選擇 CloudShell 圖示。
-
開始
cloudshell
在搜尋方塊中輸入 ,然後在搜尋結果中看到 CloudShell 選項時選擇此選項。
-
-
若要在主控台工作階段的 AWS 區域中列出您 AWS 帳戶中所有目前的 App Runner 服務,請在 CloudShell 命令列中輸入下列命令:
$
aws apprunner list-services
輸出會列出 服務的摘要資訊。
{ "ServiceSummaryList": [ { "ServiceName": "my-app-1", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceArn": "arn:aws:apprunner:us-east-2:123456789012:service/my-app-1/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-23T12:41:37Z", "Status": "RUNNING" }, { "ServiceName": "my-app-2", "ServiceId": "ab8f94cfe29a460fb8760afd2ee87555", "ServiceArn": "arn:aws:apprunner:us-east-2:123456789012:service/my-app-2/ab8f94cfe29a460fb8760afd2ee87555", "ServiceUrl": "e2m8rrrx33.us-east-1.awsapprunner.com", "CreatedAt": "2020-11-06T23:15:30Z", "UpdatedAt": "2020-11-23T13:21:22Z", "Status": "RUNNING" } ] }
-
若要取得特定 App Runner 服務的詳細說明,請使用上一個步驟中擷取的其中一個 ARNs,在 CloudShell 命令列中輸入下列命令:
$
aws apprunner describe-service --service-arn arn:aws:apprunner:us-east-2:123456789012:service/my-app-1/8fe1e10304f84fd2b0df550fe98a71fa
輸出會列出您指定服務的詳細描述。
{ "Service": { "ServiceName": "my-app-1", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceArn": "arn:aws:apprunner:us-east-2:123456789012:service/my-app-1/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-23T12:41:37Z", "Status": "RUNNING", "SourceConfiguration": { "CodeRepository": { "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" }, "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "[pip install -r requirements.txt]", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "API" } }, "AutoDeploymentsEnabled": true, "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-2:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" } }, "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" }, "HealthCheckConfiguration": { "Protocol": "TCP", "Path": "/", "Interval": 10, "Timeout": 5, "HealthyThreshold": 1, "UnhealthyThreshold": 5 }, "AutoScalingConfigurationSummary": { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-2:123456789012:autoscalingconfiguration/DefaultConfiguration/1/00000000000000000000000000000001", "AutoScalingConfigurationName": "DefaultConfiguration", "AutoScalingConfigurationRevision": 1 } } }
使用 驗證您的 App Runner 服務 AWS CloudShell
當您建立 App Runner 服務時,App Runner 會為您的服務網站建立預設網域,並在主控台中顯示它 (或在 API 呼叫結果中傳回它)。您可以使用 CloudShell 來呼叫您的網站,並驗證其是否正常運作。
例如,在您如 所述建立 App Runner 服務之後App Runner 入門,請在 CloudShell 中執行下列命令:
$
curl https://qxuadi4qwp.us-east-2.awsapprunner.com/; echo
輸出應會顯示預期的頁面內容。
