Amazon web services 如何通过Elasticbeanstalk配置文件(使用Docker)访问环境变量?

Amazon web services 如何通过Elasticbeanstalk配置文件(使用Docker)访问环境变量?,amazon-web-services,docker,amazon-elastic-beanstalk,Amazon Web Services,Docker,Amazon Elastic Beanstalk,例如,如果希望装入由环境变量定义的特定卷 我最终使用了以下代码: --- 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

例如,如果希望装入由环境变量定义的特定卷

我最终使用了以下代码:

---
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/$/;/')

您可以在bash脚本中使用
/opt/elasticbeanstalk/bin/get-config-environment

例如:

# .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')