

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# 使用 Amazon EFS 示例 AWS CLI
<a name="cli_2_efs_code_examples"></a>

以下代码示例向您展示了如何在 Amazon EFS 中使用来执行操作和实现常见场景。 AWS Command Line Interface 

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

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

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

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

### `create-file-system`
<a name="efs_CreateFileSystem_cli_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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)*中的。