

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

# 在 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 檔案系統識別碼。  
`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 ECS 檔案系統時，指定是否使用任務定義中定義的 Amazon EFS 任務 IAM 角色。如果已啟用，必須在 `EFSVolumeConfiguration` 中啟用傳輸加密。如果省略此參數，系統會使用 `DISABLED` 的預設值。如需詳細資訊，請參閱[任務的 IAM 角色](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html)。