joslinm
joslinm

Reputation: 8105

How do you get access to environment variables via Elasticbeanstalk configuration files (using Docker)?

For example, if I wish to mount a particular volume that is defined by an environment variable.

Upvotes: 6

Views: 2304

Answers (2)

stenou
stenou

Reputation: 21

You can use /opt/elasticbeanstalk/bin/get-config environment in a bash script

Example:

# .ebextensions/efs_mount.config

commands:
01_mount:
    command: "/tmp/mount-efs.sh"

files:
"/tmp/mount-efs.sh":
    mode: "000755"
    content : |
        #!/bin/bash

        EFS_REGION=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_REGION')
        EFS_MOUNT_DIR=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_MOUNT_DIR')
        EFS_VOLUME_ID=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_VOLUME_ID')

Upvotes: 1

x3mka
x3mka

Reputation: 541

I ended up using the following code:

---
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02my_setup.sh":
    owner: root
    group: root
    mode: "000755"
    content: |
      #!/bin/bash

      set -e

      . /opt/elasticbeanstalk/hooks/common.sh

      EB_CONFIG_APP_CURRENT=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
      EB_SUPPORT_FILES_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_files_dir)

      # load env vars
      eval $($EB_SUPPORT_FILES_DIR/generate_env | sed 's/$/;/')

Upvotes: 3

Related Questions