How do I pass a custom environment variable to Amazon Elastic Beanstalk (AWS EBS)?

Amazon with an elastic bean eye says:

An elastic beanstalk allows you to β€œopen the hood” and maintain full control ... even transfer environment variables through the Elastic Beanstalk console.

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

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

+86
amazon-web-services elastic-beanstalk app-config
Jun 26 2018-12-12T00:
source share
8 answers

Like a head for anyone using the .ebextensions/*.config method: you can currently add, edit, and delete environment variables in the Elastic Beanstalk web interface.

The variables are in the section Configuration β†’ Software configuration:

Environment properties

Creating vars in .ebextensions as in Onema's answer still works.

It may even be preferable, for example. if you later deploy to a different environment and are afraid to forget to manually install them, or if you agree to commit the values ​​in the original control. I use a combination of both.

+94
Jul 26 '13 at 10:08
source share

Only 5 values ​​are limited, or you can have a user environment variable name. You can do this using configuration files. Create a directory at the root of your project called

.ebextensions /

Then create a file called environment.config (this file can be called anything, but it must have the extension .config) and add the following values

 option_settings: - option_name: CUSTOM_ENV value: staging 

After the application is deployed, you will see this new value in Environmental Information β†’ Change Configuration β†’ Container

for more information check the documentation here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-options

Update

To prevent your storage values ​​from committing, such as API keys, secrets, etc., you can put a placeholder value.

 option_settings: - option_name: SOME_API_KEY value: placeholder-value-change-me 

Later, you can go to the AWS control panel (Environment Details β†’ Edit Configuration β†’ Container) and update the values ​​there. In my experience, these values ​​do not change after subsequent deployments.

Update 2 As @Benjamin stated in his comment, since the new look was rolled out on July 18, 2013, you can define any number of environment variables directly from the console:

Configuration > Software Configuration > Environment Properties

+88
Jan 23 '13 at 23:25
source share

In 2016, Java8 Tomcat8 AMI ElasticBeanstalk could not set environment variables from the web configuration. They really set the jvm -D properties.

- "The following properties are passed to the application as environment variables. More details ..."

This statement is not true for Java Tomcat ami. Amazon does not set them as environment variables. They are set as System properties, passed to the Tomcat command line as the -D property for jvm. The method in Java for getting environment variables is not the same for getting a property. System.getenv vs System.getProperty

I ssh'd in the field and checked that the environment variable was never set. However, in tomcat logs, I see that the -D property is set.

I changed my code to check both locations now as a workaround.

+20
Apr 12 '16 at 8:03
source share

Environment Information β†’ Change Configuration β†’ Container

enter image description here

+8
Jun 26 2018-12-12T00:
source share

AWS will interpret CloudFormation template strings in environment variables. You can use this to access information about your EB environment in your application:

In the AWS web interface, the following will be evaluated as the name of your environment (note the reverse ticks):

 `{ "Ref" : "AWSEBEnvironmentName" }` 

Or you can use .ebextensions/*.config and wrap the CloudFormation template in reverse ticks (`):

 { "option_settings": [ { "namespace": "aws:elasticbeanstalk:application:environment", "option_name": "ENVIRONMENT_NAME", "value": "`{ \"Ref\" : \"AWSEBEnvironmentName\" }`" } ] } 
+7
Aug 15 '16 at 18:59
source share

Alternatively, you can use the CLI Elastic Beanstalk to set environment variables.

To set the environment variable: eb setenv FOO=bar

To view environment variables: eb printenv

+4
Jul 18 '16 at 23:20
source share

This is apparently the only way to set ENV with dynamic values ​​in a beanstalk. I came up with a workaround that works for my setup of several dockers:

1) Add this to your Docker file before creating + uploading to the ECS Repository:

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

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

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

3) Connect the volume to your container

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

4) In the file .ebextensions / options.config add container_commands block like this:

 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 additional ENVs by adding more container_ commands, for example:

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

Hope this helps!

+4
Nov 17 '16 at 0:32
source share

If you are using the AWS Management Console, you just need to go to:

Configuration> Software Configuration> Environment Properties

enter image description here

0
Nov 08 '16 at 23:27
source share



All Articles