

# 在 Amazon ECS 任务定义中指定 Amazon EFS 文件系统
<a name="specify-efs-config"></a>

要为容器使用 Amazon EFS 文件系统卷，您必须在任务定义中指定卷和挂载点配置。以下任务定义 JSON 代码段显示容器的 `volumes` 和 `mountPoints` 对象的语法。

```
{
    "containerDefinitions": [
        {
            "name": "container-using-efs",
            "image": "public.ecr.aws/amazonlinux/amazonlinux:latest",
            "entryPoint": [
                "sh",
                "-c"
            ],
            "command": [
                "ls -la /mount/efs"
            ],
            "mountPoints": [
                {
                    "sourceVolume": "myEfsVolume",
                    "containerPath": "/mount/efs",
                    "readOnly": true
                }
            ]
        }
    ],
    "volumes": [
        {
            "name": "myEfsVolume",
            "efsVolumeConfiguration": {
                "fileSystemId": "fs-1234",
                "rootDirectory": "/path/to/my/data",
                "transitEncryption": "ENABLED",
                "transitEncryptionPort": integer,
                "authorizationConfig": {
                    "accessPointId": "fsap-1234",
                    "iam": "ENABLED"
                }
            }
        }
    ]
}
```

`efsVolumeConfiguration`  
类型：对象  
必需：否  
使用 Amazon EFS 卷时将指定此参数。    
`fileSystemId`  
类型：字符串  
是否必需：是  
要使用的 Amazon EFS 文件系统 ID。  
`rootDirectory`  
类型：字符串  
必需：否  
Amazon EFS 文件系统中要作为主机内的根目录挂载的目录。如果忽略此参数，将使用 Amazon EFS 卷的根目录。指定`/`与忽略此参数效果相同。  
如果在 `authorizationConfig` 中指定了 EFS 接入点，则必须省略根目录值，或者将其设置为 `/`，以便在 EFS 接入点上强制执行设置的路径。  
`transitEncryption`  
类型：字符串  
有效值：`ENABLED` \$1 `DISABLED`  
必需：否  
指定是否对 Amazon ECS 主机和 Amazon EFS 服务器之间的 Amazon EFS 传输中数据启用加密。如果使用 Amazon EFS IAM 授权，则必须启用传输加密。如果忽略此参数，将使用默认值`DISABLED`。有关更多信息，请参阅*《Amazon Elastic File System 用户指南》*中的[加密传输中数据](https://docs.aws.amazon.com/efs/latest/ug/encryption-in-transit.html)。  
`transitEncryptionPort`  
类型：整数  
必需：否  
在 Amazon ECS 主机和 Amazon EFS 服务器之间发送加密数据时要使用的端口。如果未指定传输加密端口，将使用 Amazon EFS 挂载帮助程序使用的端口选择策略。有关更多信息，请参阅*《Amazon Elastic File System 用户指南》*中的 [EFS 挂载帮助程序](https://docs.aws.amazon.com/efs/latest/ug/efs-mount-helper.html)。  
`authorizationConfig`  
类型：对象  
必需：否  
Amazon EFS 文件系统的授权配置详细信息。    
`accessPointId`  
类型：字符串  
必需：否  
要使用的接入点 ID。如果指定了接入点，则必须省略在 `efsVolumeConfiguration` 中指定的根目录值，或者将其设置为 `/`，以便在 EFS 接入点上强制执行设置的路径。如果使用接入点，则必须在`EFSVolumeConfiguration`中启用传输加密。有关更多信息，请参阅《Amazon Elastic File System 用户指南》**中的[使用 Amazon EFS 接入点工作](https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html)。  
`iam`  
类型：字符串  
有效值：`ENABLED` \$1 `DISABLED`  
必需：否  
 指定挂载 Amazon EFS 文件系统时是否使用在任务定义中定义的 Amazon ECS 任务 IAM 角色。如果启用，则必须在`EFSVolumeConfiguration`中启用传输加密。如果忽略此参数，将使用默认值`DISABLED`。有关更多信息，请参阅[适用于任务的 IAM 角色](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html)。