

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

# 使用 管理Lightsail資源 AWS CloudShell
<a name="amazon-lightsail-cloudshell"></a>

AWS CloudShell 是以瀏覽器為基礎的預先驗證 Shell，您可以直接從Amazon Lightsail主控台啟動。您可以使用 CloudShell 從命令列界面管理您的Lightsail資源。您可以使用您偏好的 shell 執行 AWS Command Line Interface (AWS CLI) 命令，例如 Bash、PowerShell 或 Z shell。無需下載或安裝命令列工具即可執行此操作。如需詳細資訊，請參閱[什麼是 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) 。

啟動 CloudShell 時，會建立以 Amazon Linux 2 為基礎的[運算環境](https://docs.aws.amazon.com/cloudshell/latest/userguide/vm-specs.html#vm-configuration)。在此環境中，可以存取廣泛的預先安裝開發工具，例如 AWS CLI。如需預先安裝的完整工具清單，請參閱《CloudShell 使用者指南》**中的[預先安裝的軟體](https://docs.aws.amazon.com/cloudshell/latest/userguide/vm-specs.html#pre-installed-software)。

## 持久性儲存
<a name="lightsail-cloudshell-persistent-storage"></a>

透過 AWS CloudShell，您可以在每個 中使用最多 1 GB 的持久性儲存 AWS 區域 體，無需額外費用。持續性儲存空間位於主目錄 (`$HOME`) 中，而且對您來說是私有的。與在每個 Shell 工作階段結束後刪除的暫時環境資源不同，主目錄中的資料會在工作階段之間持續存在。

如果您在 AWS CloudShell 中停止使用 AWS 區域，資料會在最後一個工作階段結束後保留在該區域的持久性儲存中 **120 天**。120 天後，除非您採取動作，否則您的資料會自動從該區域的持久性儲存中刪除。您可以在其中 AWS CloudShell 再次啟動，以防止移除 AWS 區域。如需有關在持續性儲存空間中保留資料的詳細資訊，請參閱《CloudShell 使用者指南》**中的[持續性儲存空間](https://docs.aws.amazon.com/cloudshell/latest/userguide/limits.html#persistent-storage-limitations)。

## AWS 區域
<a name="lightsail-cloudshell-choose-region"></a>

在 中Lightsail，CloudShell 工作階段會在 中開啟 AWS 區域 ，為實體位置提供最低的延遲。這表示 AWS 區域 可能會在工作階段之間變更。請記下 CloudShell 工作階段位於 中的哪個 AWS 區域-->，以便您可以使用 1 GB 持久性儲存。若要變更工作階段的 AWS 區域，請選擇**在新瀏覽器標籤中開啟**圖示。由此會提供在新的瀏覽器視窗中存取 CloudShell 工作階段的選項。

![CloudShell 在新的瀏覽器標籤中開啟](http://docs.aws.amazon.com/zh_tw/lightsail/latest/userguide/images/lightsail-cloudshell-new-browser-tab.png)


在新瀏覽器標籤的導覽列中，選擇目前顯示的 AWS 區域 名稱。然後選擇您要切換到 AWS 區域 的 。

![在 CloudShell AWS 區域 中變更 。](http://docs.aws.amazon.com/zh_tw/lightsail/latest/userguide/images/lightsail-cloudshell-region-select.png)


如需 CloudShell 的詳細資訊，請參閱《[CloudShell 使用者指南](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html)》。**

## 啟動和使用 AWS CloudShell
<a name="lightsail-cloudshell-launch-and-use"></a>

了解如何在 中啟動和使用 AWS CloudShell 工作階段Lightsail。如果您沒有執行 CloudShell 的許可，則必須將`arn:aws:iam::aws:policy/AWSCloudShellFullAccess`政策新增至您正在使用的 AWS Identity and Access Management (IAM) 身分。如果已經附接了 `arn:aws:iam::aws:policy/AdministratorAccess` 政策，則應該可以存取 CloudShell。如需詳細資訊，請參閱[適用於 Amazon Lightsail 的 Identity and Access Management](security_iam.md)。

**啟動 AWS CloudShell**

可以從 Amazon Lightsail 主控台啟動 CloudShell。工作階段開始後，可以切換至偏好的 Shell，例如 `Bash`、`PowerShell` 或 `Z shell`。

請完成下列步驟，以在 中啟動新的 AWS CloudShell 工作階段Lightsail：

1. 在 https：//. 登入 Lightsail主控台。 [lightsailaws.amazon.com/](https://lightsail.aws.amazon.com/)

1. 選擇主控台左下角主控台工具列中的 **CloudShell**。出現命令提示時，表示 Shell 已準備好開始互動。  
![AWS CloudShell Lightsail主控台工具列上的 。](http://docs.aws.amazon.com/zh_tw/lightsail/latest/userguide/images/lightsail-cloudshell-console-toolbar.png)

1. (選用) 若要選擇要使用的預先安裝的 Shell，請在命令列提示中輸入下列其中一個程式名稱：  
**Bash：`bash`**  
如果切換至 Bash，則命令提示中的符號會更新為 `$`。Bash 是預設的 shell AWS CloudShell。  
**PowerShell：`pwsh`**  
如果切換至 PowerShell，則命令提示中的符號會更新為 `PS>`。  
**Z Shell：`zsh`**  
如果切換至 Z Shell，則命令提示中的符號會更新為 `%`。

**Example 中的範例 Lightsail API 命令 AWS CloudShell**  
CloudShell 工作階段中預先安裝了多個命令列工具，可供您使用。在此範例中，您可以使用 Lightsail `GetInstances` API 操作，以檢視 Lightsail 帳戶中的執行個體。要了解有關 `GetInstances` API 操作的詳細資訊，請參閱《Amazon Lightsail API 參考》**中的 [GetInstances](https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetInstances.html)。  

1. 在 https：//. 登入 Lightsail主控台。 [lightsailaws.amazon.com/](https://lightsail.aws.amazon.com/)

1. 選擇主控台左下角主控台工具列中的 **CloudShell**。

1. 在 AWS CloudShell 提示後輸入下列命令：

   ```
   aws lightsail get-instances
   ```

   現在，您應該會看到 Lightsail 帳戶中的完整執行個體清單。

![Amazon Lightsail 會獲取執行個體 API 命令輸出。](http://docs.aws.amazon.com/zh_tw/lightsail/latest/userguide/images/lightsail-cloudshell-getinstances-api.png)


## 其他資訊
<a name="lightsail-cloudshell-additional-info"></a>

如需詳細資訊，請參閱下列文件 AWS CloudShell：
+ [Amazon Lightsail API 參考](https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/Welcome.html)
+ [中的常見問答集 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/faq-list.html)
+ [中支援的瀏覽器 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/browsers.html)
+ [在 中進行故障診斷 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/troubleshooting.html)
+ [在 AWS 服務 中使用 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/working-with-aws-cli.html)