## Configuring AWS ECS to have access to AWS EFS If you would like to persist data from your ECS containers, i.e. hosting databases like MySQL or MongoDB with Docker, you need to ensure that you can mount the data directory of the database in the container to volume that's not going to dissappear when your container or worse yet, the EC2 instance that hosts your containers, is restarted or scaled up or down for any reason. > Don't know how to create your own AWS ECS Cluster? Go [here](https://gist.github.com/duluca/ebcf98923f733a1fdb6682f111b1a832#file-step-by-step-how-to-for-aws-ecs-md)! ## New Cluster - Follow the directions in the referenced guide to start setting up your cluster. - When configuring the EC2 Container Instance, choose **Advanced Details** - Paste the following script in to the **User data** field: ```Bash #!/bin/bash # Install nfs-utils cloud-init-per once yum_update yum update -y cloud-init-per once install_nfs_utils yum install -y nfs-utils # Create /efs folder cloud-init-per once mkdir_efs mkdir /efs # Mount /efs cloud-init-per once mount_efs echo -e 'fs-abcd1234.efs.us-east-1.amazonaws.com:/ /efs nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0' >> /etc/fstab mount -a # Set any ECS agent configuration options echo "ECS_CLUSTER=default" >> /etc/ecs/ecs.config ``` - If you are not using the default cluster, be sure to replace the ECS_CLUSTER=default line - If you are not using the default cluster, be sure to replace the ECS_CLUSTER=default line ## Existing ECS Cluster If you have an existing ECS Cluster some ex