

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

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

AWS CloudShell 是一款基于浏览器、经过预先身份验证的外壳，您可以直接从 Amazon Lightsail 控制台启动它。您可以使用 CloudShell 通过命令行界面管理您的 Lightsail 资源。你可以使用你喜欢的外壳来运行 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，您可以免费使用每种 AWS 区域 存储空间中最多 1 GB 的永久存储空间。持久性存储位于您的主目录 (`$HOME`) 中，对您而言是私有的。与每个 Shell 会话结束后删除的临时环境资源不同的是，主目录中的数据会在不同会话之间保留。

如果您停止 AWS CloudShell 在中使用 AWS 区域，则在上次会话结束后，数据将在该区域的永久存储中保留 **120 天**。120 天后，除非您采取措施，否则您的数据将自动从该地区的持久性存储中删除。您可以通过在 AWS 区域中再次启动 AWS CloudShell 来阻止删除。有关在永久存储中保留数据的更多信息，请参阅*《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_cn/lightsail/latest/userguide/images/lightsail-cloudshell-new-browser-tab.png)


在新浏览器选项卡的导航栏中，选择当前显示的 AWS 区域 的名称。然后选择 AWS 区域 要切换到的。

![\[更改输 AWS 区域 入 CloudShell。\]](http://docs.aws.amazon.com/zh_cn/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>

了解如何在 Lightsail 中启动和使用 AWS CloudShell 会话。如果您没有运行权限 CloudShell，则必须将`arn:aws:iam::aws:policy/AWSCloudShellFullAccess`策略添加到您正在使用的 AWS Identity and Access Management (IAM) 身份。如果您已经附加了该`arn:aws:iam::aws:policy/AdministratorAccess`策略，则应该可以访问 CloudShell。有关更多信息，请参阅 [亚马逊 Lightsail 的身份和访问管理](security_iam.md)。

**启动 AWS CloudShell**

你可以 CloudShell 从 Amazon Lightsail 控制台启动。会话开始后，您可以切换到首选的 Shell，例如 `Bash`、`PowerShell` 或 `Z shell`。

完成以下步骤即可在 Lightsail 中启动新 AWS CloudShell 会话：

1. [登录 Lightsail 控制台，网址为https://lightsail.aws.amazon.com/。](https://lightsail.aws.amazon.com/)

1. 在控制台工具栏**CloudShell**上进行选择，位于控制台的左下角。当系统显示命令提示符时，表示 shell 已经准备就绪，可以进行交互。  
![\[AWS CloudShell 在 Lightsail 控制台工具栏上。\]](http://docs.aws.amazon.com/zh_cn/lightsail/latest/userguide/images/lightsail-cloudshell-console-toolbar.png)

1. （可选）要选择要使用的预安装 Shell，请在命令行提示栏中输入以下程序名称之一：  
**Bash：`bash`**  
如果切换到 Bash，则命令提示符处的符号将更新为 `$`。Bash 是中的默认外壳。 AWS CloudShell  
**PowerShell: `pwsh`**  
如果切换到 PowerShell，则命令提示符处的符号将更新为`PS>`。  
**Z shell：`zsh`**  
如果切换到 Z shell，则命令提示符处的符号将更新为 `%`。

**Example 中的 Lightsail API 命令示例 AWS CloudShell**  
会 CloudShell话中预先安装了多个命令行工具供您使用。在此示例中，您将使用 Lightsail `GetInstances` API 操作来查看您的 Lightsail 账户中的实例。要了解有关 `GetInstances` API 操作的更多信息，请参阅[GetInstances](https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetInstances.html)《*亚马逊 Lightsail API* 参考》。  

1. [登录 Lightsail 控制台，网址为https://lightsail.aws.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_cn/lightsail/latest/userguide/images/lightsail-cloudshell-getinstances-api.png)


## 附加信息
<a name="lightsail-cloudshell-additional-info"></a>

有关以下内容的更多信息，请参阅以下文档 AWS CloudShell：
+ [亚马逊 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 服务 在 in 中使用 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/working-with-aws-cli.html)