mount EFS on AWS ECS

according to official document Using Data Volumes in Tasks there is two way for ECS -> EFS mount

# efsVolumeConfiguration example

{
    "containerDefinitions": [
        {
            "memory": 128,
            "portMappings": [
                {
                    "hostPort": 80,
                    "containerPort": 80,
                    "protocol": "tcp"
                }
            ],
            "essential": true,
            "mountPoints": [
                {
                    "containerPath": "/usr/share/nginx/html",
                    "sourceVolume": "efs-html"
                }
            ],
            "name": "nginx",
            "image": "nginx"
        }
    ],
    "volumes": [
        {
            "name": "efs-html",
            "efsVolumeConfiguration": {
                "fileSystemId": "fs-1234",
                "rootDirectory": "/path/to/my/data"
            }
        }
    ],
    "family": "nginx-efs"
}

use EFS in ECS Task

  • create EFS

  • ECS -> Task definitions -> *Create Task or *Create new revision

  • in task definition -> Volumes -> Add volume

  • input EFS info

References

Use volumes

for set volume you need access EFS via instance at least once (in same VPC)

  • create EFS and

  • create Cluster for access EFS

  • wuc---qa---ECS-EFS-accessor

for access instance need to dummy accessor cluster.

and then access to instance directly

  • and don't forget key-pair set to 'wuc-devops'

To access your instance:

  1. Open an SSH client. (find out how to connect using PuTTY)

  2. Locate your private key file (wuc-devops.pem). The wizard automatically detects the key you used to launch the instance.

  3. Your key must not be publicly viewable for SSH to work. Use this command if needed:

    chmod 400 wuc-devops.pem
  4. Connect to your instance using its Public DNS:

    ec2-15-164-213-246.ap-northeast-2.compute.amazonaws.com

Example:

ssh -i "wuc-devops.pem" root@ec2-15-164-213-246.ap-northeast-2.compute.amazonaws.com

Please note that in most cases the username above will be correct, however please ensure that you read your AMI usage instructions to ensure that the AMI owner has not changed the default AMI username.If you need any assistance connecting to your instance, please see our connection documentation.

ls -da /efs

after access instance you should follow

$  sudo yum -y update  
$  sudo reboot  
$ sudo yum -y install nfs-utils

How can I create a Docker volume using Amazon EFS in Amazon ECS?

Using Data Volumes in Tasks

sudo mkdir /efs

E.G
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${EFS_DNS}:/ /efs

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-a7e9a7c6.efs.ap-northeast-2.amazonaws.com:/ /efs


echo "<html><body><h1>It works! EFS Demo :)</h1></body></html>" | sudo tee /efs/index.html

Last updated

Was this helpful?