Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 890
joslinm Avatar asked Nov 04 '14 17:11

joslinm


2 Answers

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/$/;/')
like image 196
x3mka Avatar answered Oct 18 '22 23:10

x3mka


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')
like image 35
stenou Avatar answered Oct 18 '22 23:10

stenou