【发布时间】:2021-10-10 22:49:47
【问题描述】:
我正在使用 AWS cloudformation 创建 EFS 文件系统。在将文件系统挂载到任何实例之前,我想在文件系统中有一些初始文件夹。我可以通过云形成代码实现这一点吗?如何通过代码在我的 EFS 中创建文件夹?
以下是我目前的代码。
{
"efs01": {
"type": "efs",
"depends_on": [],
"persistent": "true",
"descriptor": {
"Resources" : {
"SecurityGroup" : {
"Type": "Pipeline::SecurityGroup",
"Properties" : {
"IngressRules" : [ { "sources": [ "app01","app02" ], "ports":["TCP:NFS"] } ]
}
},
"FileSystem" : {
"Type" : "AWS::EFS::FileSystem",
"Properties" : {
"ThroughputMode": "bursting",
"ProvisionedThroughputInMibps": null
}
},
"AccessPointResource": {
"Type": "AWS::EFS::AccessPoint",
"Properties": {
"FileSystemId": {
"Ref": "FileSystem"
},
"PosixUser": {
"Uid": "ec2-user",
"Gid": "ec2-user"
},
"RootDirectory": {
"CreationInfo": {
"OwnerGid": "root",
"OwnerUid": "root",
"Permissions": "0744"
},
"Path": "/ap1"
}
}
}
}
}
}
}
【问题讨论】:
-
CloudFormation 不能直接使用 EFS——你需要一些逻辑层来为你做这件事。您可能可以创建一个AWS Lambda-backed custom resource - AWS CloudFormation,这是一个由 CloudFormation 触发的 Lambda 函数。它可以挂载 EFS 文件系统,然后运行命令来创建目录。写自定义资源有点繁琐。
-
谢谢,我正在查看docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… 的代码。为什么我需要一个初始文件夹是为我的 efs 创建一个访问点。如果我在没有根目录的情况下创建接入点,是否会在 efs 中创建根目录?
标签: amazon-web-services cloud amazon-cloudformation nfs amazon-efs