

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

# 使用 的 Amazon EFS 範例 AWS CLI
<a name="cli_efs_code_examples"></a>

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

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

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

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

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

### `create-file-system`
<a name="efs_CreateFileSystem_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-file-system`。

**AWS CLI**  
**建立加密的檔案系統**  
下列 `create-file-system` 範例會使用預設 CMK 建立加密的檔案系統。另外也會新增標籤 `Name=my-file-system`。  

```
aws efs create-file-system \
    --performance-mode generalPurpose \
    --throughput-mode bursting \
    --encrypted \
    --tags Key=Name,Value=my-file-system
```
輸出：  

```
{
    "OwnerId": "123456789012",
    "CreationToken": "console-d7f56c5f-e433-41ca-8307-9d9c0example",
    "FileSystemId": "fs-c7a0456e",
    "FileSystemArn": "arn:aws:elasticfilesystem:us-west-2:123456789012:file-system/fs-48499b4d",
    "CreationTime": 1595286880.0,
    "LifeCycleState": "creating",
    "Name": "my-file-system",
    "NumberOfMountTargets": 0,
    "SizeInBytes": {
        "Value": 0,
        "ValueInIA": 0,
        "ValueInStandard": 0
    },
    "PerformanceMode": "generalPurpose",
    "Encrypted": true,
    "KmsKeyId": "arn:aws:kms:us-west-2:123456789012:key/a59b3472-e62c-42e4-adcf-30d92example",
    "ThroughputMode": "bursting",
    "Tags": [
        {
            "Key": "Name",
            "Value": "my-file-system"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon Elastic File System 使用者指南》**中的[建立 Amazon EFS 檔案系統](https://docs.aws.amazon.com/efs/latest/ug/creating-using-create-fs.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateFileSystem](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/create-file-system.html)。

### `create-mount-target`
<a name="efs_CreateMountTarget_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-mount-target`。

**AWS CLI**  
**建立掛載目標**  
下列 `create-mount-target` 範例會為指定的檔案系統建立掛載目標。  

```
aws efs create-mount-target \
    --file-system-id fs-c7a0456e \
    --subnet-id subnet-02bf4c428bexample \
    --security-groups sg-068f739363example
```
輸出：  

```
{
    "OwnerId": "123456789012",
    "MountTargetId": "fsmt-f9a14450",
    "FileSystemId": "fs-c7a0456e",
    "SubnetId": "subnet-02bf4c428bexample",
    "LifeCycleState": "creating",
    "IpAddress": "10.0.1.24",
    "NetworkInterfaceId": "eni-02d542216aexample",
    "AvailabilityZoneId": "use2-az2",
    "AvailabilityZoneName": "us-east-2b",
    "VpcId": "vpc-0123456789abcdef0"
}
```
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[建立掛載目標](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateMountTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/create-mount-target.html)。

### `delete-file-system`
<a name="efs_DeleteFileSystem_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-file-system`。

**AWS CLI**  
**刪除檔案系統**  
以下 `delete-file-system` 範例會刪除指定的檔案系統。  

```
aws efs delete-file-system \
    --file-system-id fs-c7a0456e
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《Amazon Elastic File System 使用者指南》**中的[刪除 Amazon EFS 檔案系統](https://docs.aws.amazon.com/efs/latest/ug/delete-efs-fs.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteFileSystem](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/delete-file-system.html)。

### `delete-mount-target`
<a name="efs_DeleteMountTarget_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-mount-target`。

**AWS CLI**  
**刪除掛載目標**  
以下 `delete-mount-target` 範例會刪除指定的掛載目標。  

```
aws efs delete-mount-target \
    --mount-target-id fsmt-f9a14450
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[建立掛載目標](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteMountTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/delete-mount-target.html)。

### `describe-file-systems`
<a name="efs_DescribeFileSystems_cli_topic"></a>

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

**AWS CLI**  
**設定檔案系統**  
下列 `describe-file-systems` 範例會描述指定的檔案系統。  

```
aws efs describe-file-systems \
    --file-system-id fs-c7a0456e
```
輸出：  

```
{
    "FileSystems": [
        {
            "OwnerId": "123456789012",
            "CreationToken": "console-d7f56c5f-e433-41ca-8307-9d9c0example",
            "FileSystemId": "fs-c7a0456e",
            "FileSystemArn": "arn:aws:elasticfilesystem:us-west-2:123456789012:file-system/fs-48499b4d",
            "CreationTime": 1595286880.0,
            "LifeCycleState": "available",
            "Name": "my-file-system",
            "NumberOfMountTargets": 3,
            "SizeInBytes": {
                "Value": 6144,
                "Timestamp": 1600991437.0,
                "ValueInIA": 0,
                "ValueInStandard": 6144
            },
            "PerformanceMode": "generalPurpose",
            "Encrypted": true,
            "KmsKeyId": "arn:aws:kms:us-west-2:123456789012:key/a59b3472-e62c-42e4-adcf-30d92example",
            "ThroughputMode": "bursting",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "my-file-system"
                }
            ]
        }
    ]
}
```
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[管理 Amazon EFS 檔案系統](https://docs.aws.amazon.com/efs/latest/ug/managing.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeFileSystems](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/describe-file-systems.html)。

### `describe-mount-targets`
<a name="efs_DescribeMountTargets_cli_topic"></a>

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

**AWS CLI**  
**描述掛載目標**  
下列 `describe-mount-targets` 範例會描述指定的掛載目標。  

```
aws efs describe-mount-targets \
    --mount-target-id fsmt-f9a14450
```
輸出：  

```
{
    "MountTargets": [
        {
            "OwnerId": "123456789012",
            "MountTargetId": "fsmt-f9a14450",
            "FileSystemId": "fs-c7a0456e",
            "SubnetId": "subnet-02bf4c428bexample",
            "LifeCycleState": "creating",
            "IpAddress": "10.0.1.24",
            "NetworkInterfaceId": "eni-02d542216aexample",
            "AvailabilityZoneId": "use2-az2",
            "AvailabilityZoneName": "us-east-2b",
            "VpcId": "vpc-0123456789abcdef0"
        }
    ]
}
```
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[建立掛載目標](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeMountTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/describe-mount-targets.html)。

### `describe-tags`
<a name="efs_DescribeTags_cli_topic"></a>

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

**AWS CLI**  
**描述檔案系統的標籤**  
下列 `describe-tags` 範例描述指定的檔案系統標籤。  

```
aws efs describe-tags \
    --file-system-id fs-c7a0456e
```
輸出：  

```
{
    "Tags": [
        {
            "Key": "Name",
            "Value": "my-file-system"
        },
        {
            "Key": "Department",
            "Value": "Business Intelligence"
        }
    ]
}
```
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[管理檔案系統標籤](https://docs.aws.amazon.com/efs/latest/ug/manage-fs-tags.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/describe-tags.html)。

### `list-tags-for-resource`
<a name="efs_ListTagsForResource_cli_topic"></a>

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

**AWS CLI**  
**擷取資源的標籤**  
下列 `list-tags-for-resource` 範例會擷取與指定之檔案系統相關聯的標籤。  

```
aws efs list-tags-for-resource \
    --resource-id fs-c7a0456e
```
輸出：  

```
{
    "Tags": [
        {
            "Key": "Name",
            "Value": "my-file-system"
        },
        {
            "Key": "Department",
            "Value": "Business Intelligence"
        }
    ]
}
```
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[管理檔案系統標籤](https://docs.aws.amazon.com/efs/latest/ug/manage-fs-tags.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/list-tags-for-resource.html)。

### `tag-resource`
<a name="efs_TagResource_cli_topic"></a>

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

**AWS CLI**  
**標記資源**  
下列 `tag-resource` 範例可將標籤 `Department=Business Intelligence` 新增至檔案系統。  

```
aws efs tag-resource \
    --resource-id fs-c7a0456e \
    --tags Key=Department,Value="Business Intelligence"
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[管理檔案系統標籤](https://docs.aws.amazon.com/efs/latest/ug/manage-fs-tags.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/tag-resource.html)。

### `untag-resource`
<a name="efs_UntagResource_cli_topic"></a>

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

**AWS CLI**  
**將標籤從資源中移除**  
下列 `untag-resource` 範例會從指定檔案系統中移除具有 `Department` 標籤索引的標籤。  

```
aws efs untag-resource \
    --resource-id fs-c7a0456e \
    --tag-keys Department
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*Amazon Elastic File System 使用者指南*》中的[管理檔案系統標籤](https://docs.aws.amazon.com/efs/latest/ug/manage-fs-tags.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/efs/untag-resource.html)。