为 ECS 集群上的 EFS 卷指定正确的 AZ 挂载点 - CloudFormation

Specify correct AZ mount point for EFS volume on ECS Cluster - CloudFormation

查看 this 挂载 EFS 卷以在 ECS 中保留 docker 卷的示例,我不确定如何为实例所在的可用区提供正确的挂载点。我的堆栈中有两个可用区,需要正确的挂载点插入 cfn-init 的这一部分:

01_mount:
    command: !Join [ "", [ "mount -t nfs4 -o nfsvers=4.1 ", !ImportValue '!Ref FileSystem', ".efs.", !Ref 'AWS::Region', ".amazonaws.com:/ /", !Ref MountPoint ] ]
02_fstab:
    command: !Join [ "", [ "echo \"", !ImportValue '!Ref FileSystem', ".efs.", !Ref 'AWS::Region', ".amazonaws.com:/ /", !Ref MountPoint, " nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0\" >> /etc/fstab" ] ]
03_permissions:
    command: !Sub "chown -R ec2-user:ec2-user /${MountPoint}"

如果您在 VPC 中使用 DNS 设置并且在 VPC 配置中具有其他必要的先决条件,则在挂载 EFS 文件系统时不再需要使用特定于可用性区域的挂载目标。

File system DNS name – Using the file system's DNS name is your simplest mounting option. The file system DNS name will automatically resolve to the mount target’s IP address in the Availability Zone of the connecting Amazon EC2 instance. You can get this DNS name from the console, or if you have the file system ID, you can construct it using the following convention:

file-system-id.efs.aws-region.amazonaws.com

(emphasis added)

http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html

此功能于 2016 年 12 月推出,即服务发布预览版几个月后。以前,上面显示的主机名样式必须加上您想要的可用区。该选项仍然受支持,但此选项有效地消除了这种笨拙的配置要求,无论是在 docker 还是在具有 fstab 挂载的普通实例上。

请参阅 VPC 配置元素的参考页面,此解决方案必须到位才能在您的 VPC 中运行。