How do you pass custom environment variable on Ama

2019-01-02 22:36发布

The Amazon Elastic Beanstalk blurb says:

Elastic Beanstalk lets you "open the hood" and retain full control ... even pass environment variables through the Elastic Beanstalk console.

http://aws.amazon.com/elasticbeanstalk/

How to pass other environment variables besides the one in the Elastic Beanstalk configuration?

7条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-02 23:09

This seems to be the only way to set ENVs with dynamic values in beanstalk. I came up with a workaround that works for my multi-docker setup:

1) Add this to your Dockerfile before building + uploading to your ECS repository:

CMD eval `cat /tmp/envs/env_file$`; <base image CMD goes here>;

2) In your Dockerrun.aws.json file create a volume:

{
    "name": "env-file",
    "host": {
        "sourcePath": "/var/app/current/envs"
    }
}

3) Mount volume to your container

{
  "sourceVolume": "env-file",
  "containerPath": "/tmp/envs",
  "readOnly": true
}

4) In your .ebextensions/options.config file add a container_commands block like so:

container_commands:
  01_create_mount:
    command: "mkdir -p envs/"
  02_create_env_file:
    command: { "Fn::Join" : [ "", [ 'echo "', "export ENVIRONMENT_NAME=" , { "Ref", "RESOURCE" }, ';" > envs/env_file;' ] ] }

5) eb deploy and your ENVS should be available in your docker container

You can add more ENVs by adding more container_commands like:

  02_create_env_file_2:
    command: { "Fn::Join" : [ "", [ 'echo "', "export ENVIRONMENT_NAME_2=" , { "Ref", "RESOURCE2" }, ';" >> envs/env_file;' \] \] }

Hope this helps!

查看更多
登录 后发表回答