

# 使用 AWS CLI 的 Storage Gateway 示例
<a name="cli_storage-gateway_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与 Storage Gateway 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `describe-gateway-information`
<a name="storage-gateway_DescribeGatewayInformation_cli_topic"></a>

以下代码示例演示了如何使用 `describe-gateway-information`。

**AWS CLI**  
**描述网关**  
以下 `describe-gateway-information` 命令将返回有关指定网关的元数据。在命令中使用网关的 Amazon 资源名称（ARN）指定要描述的网关。  
此示例指定账户 `123456789012` 中 ID 为 `sgw-12A3456B` 的网关：  

```
aws storagegateway describe-gateway-information --gateway-arn "arn:aws:storagegateway:us-west-2:123456789012:gateway/sgw-12A3456B"
```
此命令将输出一个 JSON 数据块，其中包含有关网关的元数据，如名称、网络接口、已配置时区和状态（网关运行与否）。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeGatewayInformation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/storagegateway/describe-gateway-information.html)。

### `list-file-shares`
<a name="storage-gateway_ListFileShares_cli_topic"></a>

以下代码示例演示了如何使用 `list-file-shares`。

**AWS CLI**  
**列出文件共享**  
以下 `command-name` 示例列出您的 AWS 账户中可用的小组件。  

```
aws storagegateway list-file-shares \
    --gateway-arn arn:aws:storagegateway:us-east-1:209870788375:gateway/sgw-FB02E292
```
输出：  

```
{
    "FileShareInfoList": [
        {
            "FileShareType": "NFS",
            "FileShareARN": "arn:aws:storagegateway:us-east-1:111122223333:share/share-2FA12345",
            "FileShareId": "share-2FA12345",
            "FileShareStatus": "AVAILABLE",
            "GatewayARN": "arn:aws:storagegateway:us-east-1:111122223333:gateway/sgw-FB0AAAAA"
        }
    ],
    "Marker": null
}
```
有关更多信息，请参阅《AWS Storage Gateway 服务 API 参考》**中的 [ListFileShares](https://docs.aws.amazon.com/storagegateway/latest/APIReference/API_ListFileShares.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListFileShares](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/storagegateway/list-file-shares.html)。

### `list-gateways`
<a name="storage-gateway_ListGateways_cli_topic"></a>

以下代码示例演示了如何使用 `list-gateways`。

**AWS CLI**  
**列出账户的网关**  
以下 `list-gateways` 命令将列出为账户定义的所有网关：  

```
aws storagegateway list-gateways
```
此命令将输出包含网关 Amazon 资源名称（ARN）列表的 JSON 数据块。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListGateways](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/storagegateway/list-gateways.html)。

### `list-volumes`
<a name="storage-gateway_ListVolumes_cli_topic"></a>

以下代码示例演示了如何使用 `list-volumes`。

**AWS CLI**  
**列出为网关配置的卷**  
以下 `list-volumes` 命令将返回为指定网关配置的卷列表。在命令中使用网关的 Amazon 资源名称（ARN）指定要描述的网关。  
此示例指定账户 `123456789012` 中 ID 为 `sgw-12A3456B` 的网关：  

```
aws storagegateway list-volumes --gateway-arn "arn:aws:storagegateway:us-west-2:123456789012:gateway/sgw-12A3456B"
```
此命令将输出一个 JSON 数据块，其中包含带有每个卷的类型和 ARN 的卷列表。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListVolumes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/storagegateway/list-volumes.html)。

### `refresh-cache`
<a name="storage-gateway_RefreshCache_cli_topic"></a>

以下代码示例演示了如何使用 `refresh-cache`。

**AWS CLI**  
**刷新文件共享缓存**  
以下 `refresh-cache` 示例刷新指定文件共享的缓存。  

```
aws storagegateway refresh-cache \
    --file-share-arn arn:aws:storagegateway:us-east-1:111122223333:share/share-2FA12345
```
输出：  

```
{
    "FileShareARN": "arn:aws:storagegateway:us-east-1:111122223333:share/share-2FA12345",
    "NotificationId": "4954d4b1-abcd-ef01-1234-97950a7d3483"
}
```
有关更多信息，请参阅《AWS Storage Gateway 服务 API 参考》**中的 [ListFileShares](https://docs.aws.amazon.com/storagegateway/latest/APIReference/API_RefreshCache.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [RefreshCache](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/storagegateway/refresh-cache.html)。