Search code examples
amazon-ecs

How can I add a persistent volume to my API running in ECS?


I'm trying to persist the data stored in my static folder because the users can upload images and store in that folder, generally when I work with docker is just use a volume mounting the /static folder and pointing to some host folder, but seems that I'm not doing this correctly.

enter image description here

Inside my ECS task definition I created the volume /static with name static...I run my service using this task definition, then I entered the corresponding docker

docker exec -it <id for my service> bash

I navigate across the folders but I can't found any /static folder in any path

what am I ignoring? what is the simplest way to add a folder where I can persist data in my ECS

thanks guy and sorry for this super noob question


Solution

  • It looks like you've only added the volume to the TaskDefinition and not referenced it in any ContainerDefinitions. If you hover over the information icon beside "Name" in your screenshot the info message will read:

    The name of the volume to use in the container definition Mount points as Source volume.

    So, you need to create to reference the above mount in the "mountPoints" of your ContainerDefinition, this will add the static folder to your container.

    E.g. The following is an JSON task-definition with everything except mounts removed:

    {
      "containerDefinitions": [
        {
          "mountPoints": [
            {
              "readOnly": null,
              "containerPath": "/static",
              "sourceVolume": "static"
            }
          ]
        }
      ],
      "volumes": [
        {
          "fsxWindowsFileServerVolumeConfiguration": null,
          "efsVolumeConfiguration": null,
          "name": "static",
          "host": {
            "sourcePath": "/static"
          },
          "dockerVolumeConfiguration": null
        }
      ]
    }