

AWS App Runner 自 2026 年 4 月 30 日起，不再開放給新客戶。如果您想要使用 App Runner，請在該日期之前註冊。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS App Runner 可用性變更](https://docs.aws.amazon.com/apprunner/latest/dg/apprunner-availability-change.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 AWS CloudShell 來使用 AWS App Runner
<a name="api-cshell"></a>

AWS CloudShell 是以瀏覽器為基礎的預先驗證 Shell，您可以直接從 啟動 AWS 管理主控台。您可以使用您偏好的 shell (Bash、PowerShell 或 Z shell AWS App Runner) 對 AWS 服務 （包括） 執行 AWS CLI 命令。另外，您無需下載或安裝命令列工具即可執行此操作。

您可以從 [AWS CloudShell 啟動 AWS 管理主控台](https://docs.aws.amazon.com/cloudshell/latest/userguide/working-with-cloudshell.html#launch-options)，而且您用來登入主控台的 AWS 登入資料會自動在新的 shell 工作階段中使用。此預先驗證 AWS CloudShell 使用者可讓您在使用第 2 AWS CLI 版 （預先安裝在 Shell 的運算環境中） 與 App Runner 等 AWS 服務互動時，略過設定登入資料。

**Topics**
+ [取得 的 IAM 許可 AWS CloudShell](#api-cshell.permissions)
+ [使用 與 App Runner 互動 AWS CloudShell](#api-cshell.call-apprunner)
+ [使用 驗證您的 App Runner 服務 AWS CloudShell](#api-cshell.call-your-service)

## 取得 的 IAM 許可 AWS CloudShell
<a name="api-cshell.permissions"></a>

 AWS Identity and Access Management管理員可以使用 提供的存取管理資源，將許可授予 IAM 使用者，讓他們可以存取 AWS CloudShell 和使用環境的功能。

管理員授予使用者存取權的最快速方式是透過 AWS 受管政策。[AWS 受管政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#aws-managed-policies)是由 AWS建立並管理的獨立政策。下列適用於 CloudShell 的 AWS 受管政策可以連接到 IAM 身分：
+ `AWSCloudShellFullAccess`：授予許可，以 AWS CloudShell 使用 並完整存取所有功能。

 如果您想要限制 IAM 使用者可以執行的動作範圍 AWS CloudShell，您可以建立使用 `AWSCloudShellFullAccess`受管政策做為範本的自訂政策。如需限制 CloudShell 中使用者可用的動作的詳細資訊，請參閱*AWS CloudShell 《 使用者指南*》中的[使用 IAM 政策管理 AWS CloudShell 存取和用量](https://docs.aws.amazon.com/cloudshell/latest/userguide/sec-auth-with-identities.html)。

**注意**  
您的 IAM 身分也需要政策，授予對 App Runner 進行呼叫的許可。如需詳細資訊，請參閱[App Runner 如何與 IAM 搭配使用](security_iam_service-with-iam.md)。

## 使用 與 App Runner 互動 AWS CloudShell
<a name="api-cshell.call-apprunner"></a>

 AWS CloudShell 從 啟動後 AWS 管理主控台，您可以立即開始使用命令列界面與 App Runner 互動。

在下列範例中，您會使用 CloudShell AWS CLI 中的 擷取其中一個 App Runner 服務的相關資訊。

**注意**  
在 AWS CLI 中使用 時 AWS CloudShell，您不需要下載或安裝任何其他資源。此外，因為您已經在 Shell 中驗證身分，因此無需設定憑證即可呼叫。

**Example 使用 擷取 App Runner 服務資訊 AWS CloudShell**  

1. 從 中 AWS 管理主控台，您可以選擇導覽列上可用的下列選項來啟動 CloudShell：
   +  選擇 CloudShell 圖示。
   + 開始**cloudshell**在搜尋方塊中輸入 ，然後在搜尋結果中看到 **CloudShell** 選項時選擇該選項。

1. 若要在主控台工作階段的 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"
       }
     ]
   }
   ```

1. 若要取得特定 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
<a name="api-cshell.call-your-service"></a>

當您[建立 App Runner 服務](manage-create.md)時，App Runner 會為您的服務網站建立預設網域，並在主控台中顯示它 （或在 API 呼叫結果中傳回它）。您可以使用 CloudShell 對網站進行呼叫，並確認其正常運作。

例如，在如 中所述建立 App Runner 服務之後[App Runner 入門](getting-started.md)，請在 CloudShell 中執行下列命令：

```
$ curl https://qxuadi4qwp.us-east-2.awsapprunner.com/; echo
```

輸出應會顯示預期的頁面內容。

![\[瀏覽器視窗 AWS CloudShell 顯示 命令，以顯示 App Runner 服務頁面的內容\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/images/api-cshell-curl.png)
