8

I'm looking for some way to mount a S3 Storage Bucket (for example) as Docker volume in an Elastic Beanstalk Docker Container.

Since i can't change the application code, i have to configure that part in the Dockerrun.aws.json file using Docker volumes.

I need to mount a file for a single configuration file and a volume for a file directory in my application.

Here's my Dockerrun.aws.json file.

{
    "AWSEBDockerrunVersion": "1",

    "Image": {
        "Name": "app"
    },
    "Ports": [
        {
            "ContainerPort": 8080,
            "HostPort" : 80
        }

    ],
    "environment": [
        {
          "name": "app_DB_MYSQL",
          "value": ""
        },
        {
            "name": "app_DB_USERNAME",
            "value": "app"
        },
        {
            "name": "app_DB_PASSWORD",
            "value": ""
        },
        {
            "name": "app_DB_DATABASE",
            "value": "app"
        }
      ],

      "volumes": [
        {
            "HostDirectory": "files",
            "containerPath": "/usr/src/app/files",
        },

        {
            "HostDirectory": "configuration.yaml",
            "containerPath": "/usr/src/app/config/configuration.yaml",
        }
      ],

    "Logging": "/var/log",

}
Aurelien
  • 688
  • 1
  • 9
  • 22
  • have you been able to find a solution to this? – Ashwin K Joseph Jul 02 '20 at 12:36
  • The only thing I can think of is to have a multi-container setup with both being mounted to the same volume. The first one would be your application while the second one would be watcher which watches for new files and then uploads them to S3. I am not sure how dependable or good of a solution this is. – Ashwin K Joseph Jul 02 '20 at 12:38

1 Answers1

0

For persistent storage Elastic Beanstalk with Amazon Elastic File System is generally used:

  1. edit storage-efs-createfilesystem.config, add it to the .ebextensions directory and deploy
  2. then remove storage-efs-createfilesystem.config from .ebextensions, edit and add storage-efs-mountfilesystem.config to .ebextensions, edit Dockerrun.aws.json to match storage-efs-mountfilesystem.config and redeploy.

Sample storage-efs-mountfilesystem.config extract:

option_settings:
  aws:elasticbeanstalk:application:environment:
    FILE_SYSTEM_ID: 'fs-REPLACE_THIS_WITH_ID!'
    MOUNT_DIRECTORY: '/efs'

Sample Dockerrun.aws.json extract:

"Volumes": [
    {
        "HostDirectory": "/efs/app",
        "ContainerDirectory": "/usr/src/app",
    }
pba
  • 700
  • 8
  • 18