

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

# 使用以下方式管理 Lightsail 资源 AWS CloudShell

AWS CloudShell 是一款基于浏览器的预认证外壳，您可以直接从亚马逊 Lightsail 控制台启动。您可以使用 CloudShell 命令行界面管理您的 Lightsail 资源。你可以使用你喜欢的 shell 来运行 AWS Command Line Interface (AWS CLI) 命令，比如 Bash 或 Z shell。 PowerShell您无需下载或安装命令行工具，即可完成此操作。有关更多信息，请参阅[什么是 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html)。

启动时 CloudShell，将创建基于亚马逊 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)Pre-installed 软件。

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

使用 AWS CloudShell，每个存储器中最多可使用 1 GB 的永久存储空间 AWS 区域 ，无需额外付费。持久性存储位于您的主目录 (`$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 在新浏览器选项卡中打开](https://docs.aws.amazon.com/zh_cn/lightsail/latest/userguide/images/lightsail-cloudshell-new-browser-tab.png)


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

![改 AWS 区域 进 CloudShell。](https://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 从亚马逊 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 控制台工具栏上。](https://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 操作的更多信息，请参阅*亚马逊 Lightsail API 参考[GetInstances](https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetInstances.html)中的内容。*  

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

1. 在控制台工具栏**CloudShell**上选择。

1. 在 AWS CloudShell 提示符后输入以下命令：

   ```
   aws lightsail get-instances
   ```

   现在，您应该会看到您的 Lightsail 账户中实例的完整列表。

![亚马逊 Lightsail 获取实例 API 命令输出。](https://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)