stelligent / mu

A full-stack DevOps on AWS framework
https://getmu.io
MIT License
974 stars 135 forks source link

EFS Support for Volumes #289

Open waynerobinson opened 6 years ago

waynerobinson commented 6 years ago

If I wanted to EFS for shared volumes in containers as per https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_efs.html would I modify the ContainerInstance config in https://github.com/stelligent/mu/blob/develop/templates/assets/env-ecs.yml via a plugin to add the extra libraries/config required?

By the way, this is a really cool project that goes into a lot more depth compared to the version of this I was building manually. 👍

timbaileyjones commented 6 years ago

Hi Wayne. I am doing a shared EFS volume shared across instances spawned by 4 ASGs. mu doesn't have specific support for EFS, but you can do it through custom CFN.

In addition to declaring the EFSFilesystem, an incoming SG for port 2049, and a MountTarget for each of the AZs my EC2 instances will be in, I am passing in the DNSName of the EFSFilesystem to a boot script (userdata) as an environment variables.

      WebLaunchConfig:
        Type: AWS::AutoScaling::LaunchConfiguration
        Metadata:
          AWS::CloudFormation::Init:
            config:
              commands:
                01_configure_and_start:
                  env: 
                    EFS_DNS_NAME: 
                      Fn::Sub: "${EFSFileSystem}.efs.${AWS::Region}.amazonaws.com"
                  command: 'python3 ./configure-and-start.py 2>&1 | tee configure-and-start.txt'

The configure-and-start.py appends a line to /etc/fstab, and the executes the mount command.

       efs = '%s:/\t/srv\tnfs4\tnfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev\t0\t0' % (vars['EFS_DNS_NAME'])
       # writes 'efs' to /etc/fstab, and runs 'mount /srv' via os.system

Hope it helps!

waynerobinson commented 6 years ago

That sounds like a really great start, thanks for that.