Is it posssible to reference the PARAM1 / PARAM2 etc.. container environment properties from the .ebextensions config files. If so, how? I tried $PARAM1 but it seemed to be an empty value.
I want to set the hostname on startup to contain DEV, QA or PROD, which I pass to my container via the PARAM1 environment variable.
commands:
01-set-correct-hostname:
command: hostname myappname{$PARAM1}.com
It turns out you can only do this in the
container_commands
section, not thecommands
section.This works:
See http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands for more details.
Here is what worked for me. I tried the accepted approach and it did not produce the desired result (curly braces were included in the output). Troubleshooting commands that are executed from a .config file when uploading to Elastic Beanstalk is also a bit of a challenge (or I just don't know exactly where to look).
AWS Environment:
Elastic Beanstalk Environment Properties (Configuration -> Software Configuration -> Environment Properties):
Sample .config File included in the .ebextensions folder in the deployment artifact:
After the artifact has been deployed using Elastic Beanstalk the /tmp directory within an EC2 instance will contain the following files (note curly braces and position of $):
Accepted answer is quite outdated.
Now you can use
/opt/elasticbeanstalk/support/envvars
file which is already a shell script ready to be sourced:Update:
After some deeper investigation turns out that
container_commands:
include your environment variables, butcommands:
not.To make the environment variables available at the commands stage I parse them into a bash sourceable file.
000001.envvars.config
Then I use:-
in subsequent commands.
This blog describes in detail various options on how you can achieve this.
https://www.onica.com/blog/how-to-call-and-export-variables-in-elastic-beanstalk/