

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

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

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Storage Gateway 執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `describe-gateway-information`。

**AWS CLI**  
**描述閘道**  
下列 `describe-gateway-information` 命令會傳回指定閘道的相關中繼資料。若要指定要描述的閘道，請在命令中使用閘道的 Amazon Resource Name (ARN)。  
此範例會在帳戶 `sgw-12A3456B` 中指定 ID 為 `123456789012` 的閘道：  

```
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_2_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_2_topic"></a>

以下程式碼範例顯示如何使用 `list-gateways`。

**AWS CLI**  
**列出帳戶的閘道**  
下列 `list-gateways` 命令會列出為帳戶定義的所有閘道：  

```
aws storagegateway list-gateways
```
此命令會輸出 JSON 區塊，其中包含閘道 Amazon Resource Name (ARN) 的清單。  
+  如需 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_2_topic"></a>

以下程式碼範例顯示如何使用 `list-volumes`。

**AWS CLI**  
**列出為閘道設定的磁碟區**  
下列 `list-volumes` 命令會傳回為指定閘道設定的磁碟區清單。若要指定要描述的閘道，請在命令中使用閘道的 Amazon Resource Name (ARN)。  
此範例會在帳戶 `sgw-12A3456B` 中指定 ID 為 `123456789012` 的閘道：  

```
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_2_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)。