5

Userdata on launch configuration:

#!/bin/bash
echo ECS_CLUSTER=prodcluster >> /etc/ecs/ecs.config

sudo yum install -y nfs-utils 
sudo mkdir /home/ec2-user/web_file_uploads 
sudo chmod 777 /home/ec2-user/web_file_uploads 

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-abcdef.efs.ap-southeast-2.amazonaws.com:/ /home/ec2-user/web_file_uploads 

Task definition:

{
  "networkMode": "bridge",
  "containerDefinitions": [
    {
      "portMappings": [
        ...
      ],
      "essential": true,
      "mountPoints": [
        {
          "containerPath": "/src/temp_uploads/",
          "sourceVolume": "web_file_uploads",
          "readOnly": null
        }
      ],
      "name": "webapp",
      "readonlyRootFilesystem": null,
      "image": "911911911.dkr.ecr.ap-southeast-2.amazonaws.com/webapp:release6",
      "memoryReservation": 150
    }
  ],
  "volumes": [
    {
      "host": {
        "sourcePath": "/home/ec2-user/web_file_uploads"
      },
      "name": "web_file_uploads"
    }
  ],
  "family": "webapp-task"
}

Note: I have added required ports to security group. src/temp_uploads folder is required to have within all other container instances launched with this task definition.

Problem: If I mount it manually using sudo mount ... folder1, put some files there and mount the same to sudo mount ... folder2 folder 2 contains the changes which shows it mounts correctly.

The problem is the volume mapped through the task definition doesn't map efs. Instead it puts/use content actually inside /home/ec2-user/web_file_uploads. How to make this volume actually mapped to efs

2
  • Any best practices I missed are welcome to mention
    – sithumc
    Apr 4, 2017 at 4:34
  • I'm not sure if I understand your problem well. Do you want to have shared content in folder1 and folder2 when you put in folder1 files?!?
    – dsmsk80
    Apr 4, 2017 at 13:06

1 Answer 1

2

Modify the lunch configuration to restart docker service right after mounting EFS. Then only ECS will use the mounted EFS as volume. Otherwise it will use the original directory (mount will be ignored).

#!/bin/bash
echo ECS_CLUSTER=prodcluster >> /etc/ecs/ecs.config
sudo yum install -y nfs-utils

sudo stop ecs
sudo mkdir /home/ec2-user/web_file_uploads
sudo chmod 777 /home/ec2-user/web_file_uploads
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-abcdef.efs.ap-southeast-2.amazonaws.com:/ /home/ec2-user/web_file_uploads
sudo service docker restart
sudo start ecs

Note: ECS service will stop after restarting docker service as ECS Agent runs inside docker. You need to start ECS Service afterwards.

1
  • Is it possible to do this without using chmod 777? Sep 15, 2018 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .