

# 在 Amazon ECS 任务定义中指定适用于 Windows File Server 的 FSx 文件系统
<a name="specify-wfsx-config"></a>

要为容器使用适用于 Windows File Server 的 FSx 文件系统卷，请在任务定义中指定卷和挂载点配置。以下任务定义 JSON 代码段显示容器的 `volumes` 和 `mountPoints` 对象的语法。

```
{
    "containerDefinitions": [
        {
            "entryPoint": [
                "powershell",
                "-Command"
            ],
            "portMappings": [],
            "command": ["New-Item -Path C:\\fsx-windows-dir\\index.html -ItemType file -Value '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>It Works!</h2> <p>You are using Amazon FSx for Windows File Server file system for persistent container storage.</p>' -Force"],
            "cpu": 512,
            "memory": 256,
            "image": "mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019",
            "essential": false,
            "name": "container1",
            "mountPoints": [
                {
                    "sourceVolume": "fsx-windows-dir",
                    "containerPath": "C:\\fsx-windows-dir",
                    "readOnly": false
                }
            ]
        },
        {
            "entryPoint": [
                "powershell",
                "-Command"
            ],
            "portMappings": [
                {
                    "hostPort": 443,
                    "protocol": "tcp",
                    "containerPort": 80
                }
            ],
            "command": ["Remove-Item -Recurse C:\\inetpub\\wwwroot\\* -Force; Start-Sleep -Seconds 120; Move-Item -Path C:\\fsx-windows-dir\\index.html -Destination C:\\inetpub\\wwwroot\\index.html -Force; C:\\ServiceMonitor.exe w3svc"],
            "mountPoints": [
                {
                    "sourceVolume": "fsx-windows-dir",
                    "containerPath": "C:\\fsx-windows-dir",
                    "readOnly": false
                }
            ],
            "cpu": 512,
            "memory": 256,
            "image": "mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019",
            "essential": true,
            "name": "container2"
        }
    ],
    "family": "fsx-windows",
    "executionRoleArn": "arn:aws:iam::111122223333:role/ecsTaskExecutionRole",
    "volumes": [
        {
            "name": "fsx-windows-dir",
            "fsxWindowsFileServerVolumeConfiguration": {
                "fileSystemId": "fs-0eeb5730b2EXAMPLE",
                "authorizationConfig": {
                    "domain": "example.com",
                    "credentialsParameter": "arn:arn-1234"
                },
                "rootDirectory": "share"
            }
        }
    ]
}
```

`FSxWindowsFileServerVolumeConfiguration`  
类型：对象  
必需：否  
当您使用适用于 Windows File Server 的 FSx [https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html)文件系统进行任务存储时，指定此参数。    
`fileSystemId`  
类型：字符串  
是否必需：是  
要使用的适用于 Windows File Server 的 FSx 文件系统 ID。  
`rootDirectory`  
类型：字符串  
是否必需：是  
适用于 Windows File Server 的 FSx 文件系统中要作为主机内的根目录挂载的目录。  
`authorizationConfig`    
`credentialsParameter`  
类型：字符串  
是否必需：是  
授权凭证选项：  
+ [Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 密钥的 Amazon 资源名称（ARN）。
+ [Secrets Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/integration-ps-secretsmanager.html) 参数的 Amazon 资源名称（ARN）。  
`domain`  
类型：字符串  
是否必需：是  
由 [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html)（AWS Managed Microsoft AD）目录托管的完全限定域名或自托管 EC2 Active Directory。

## 存储适用于 Windows File Server 的 FSx 卷凭证的方法
<a name="creds"></a>

存储凭证的凭证有两种不同的方法，以便与凭证参数一起使用。
+ **AWS Secrets Manager 密钥**

  此凭证可以在 AWS Secrets Manager 控制台中使用*其他密钥类型*类别。您可以为每个键/值对、用户名/管理员和密码/{{password}} 添加一行。
+ **Systems Manager 参数**

  通过以下示例代码片段中的形式输入文本，可以在 Systems Manager 参数控制台中创建此凭证。

  ```
  {
    "username": "admin",
    "password": {{"password"}}
  }
  ```

任务定义 `FSxWindowsFileServerVolumeConfiguration` 参数中的 `credentialsParameter` 将保存密钥 ARN 或 Systems Manager 参数 ARN。有关更多信息，请参阅 *Secrets Manager用户指南*中的[什么是 AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)以及 *Systems Manager 用户指南*中的 [Systems Manager 参数存储](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)。