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
Elastic Beanstalk lets you enter the environment variables for each environment using the management panel. On AWS, open Elastic Beanstalk. Go to your Application > Environment > Configuration > Software Configuration . Under Environment Properties you will find a list of properties you can configure.
ebextensions, see the Elastic Beanstalk Configuration Files Repository . Location – Place all of your configuration files in a single folder, named . ebextensions , in the root of your source bundle.
In AWS Elastic Beanstalk, you can create a load-balanced, scalable environment or a single-instance environment. The type of environment that you require depends on the application that you deploy.
Each component application must have an env. yaml configuration file in its application source bundle that specifies the parameters used to create its environment.
And to access environment variables use Fn::GetOptionSetting. Environment variables are in aws:elasticbeanstalk:application:environment namespace. Below example access an environment variable ENVIRONMENT in source option of files:
Create a .ebextension file in your application source bundle and include the following: Note: The configuration file in step 1 is called setvars.config. 2. Save the .ebextension file, and then deploy it to your Elastic Beanstalk environment.
However, you can make any configuration change in Elastic Beanstalk configuration files identically using either YAML or JSON. When you are developing or testing new configuration files, launch a clean environment running the default application and deploy to that.
1. Open the Elastic Beanstalk console. 2. Select your application, and then choose Configuration from the navigation pane. 3. For the Software category, choose Modify. 4. In the Environment properties section, enter the key-value pairs for the environment properties that you want to pass to your instances. 5.
It turns out you can only do this in the container_commands
section, not the commands
section.
This works:
container_commands: 01-set-correct-hostname: command: "hostname myappname{$PARAM1}.com"
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:
container_commands: 0_test-variable: cwd: /tmp command: "touch ${HELLO_VARIABLE}_0_.txt" 1_test-variable: cwd: /tmp command: "touch {$HELLO_VARIABLE}_1_.txt" 2_test-variable: cwd: /tmp command: "touch $HELLO_VARIABLE_2_.txt"
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 $):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With