Home > front end >  AWS Cloudformation - Create initial folders in EFS
AWS Cloudformation - Create initial folders in EFS

Time:10-11

I am using AWS cloudformation to create an EFS file system. I want to have some intial folders in the file system before mounting it to any instances. Can I achieve this though the cloud formation code? How can I create a folder in my EFS through code?

Following is the code I have so far.

{
  "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"
            }
          }
        }
      }
    }
  }
}

CodePudding user response:

How can I create a folder in my EFS through code?

You don't have to do anything. AWS will create /ap1 for you automatically on the EFS. But any application that is going to use your AccessPointResource will not see it. Instead, they will be bound to /ap1 and never be able to see what's at / of the EFS.

This means that for any application that mounts EFS using your AccessPointResource, the root of the mount is /. /ap1 will only be visible to access points that use "Path": "/".

  • Related