AWS Cloud9 is no longer available to new customers. Existing customers of
AWS Cloud9 can continue to use the service as normal.
Learn more
The AWS Cloud9 Integrated Development Environment (IDE) supports setting custom environment variables. You can set custom environment variables in the AWS Cloud9 IDE in the following ways.
Set Command-Level Custom Environment Variables
You can set command-level custom environment variables as you run a command in your AWS Cloud9 development environment. To test this behavior, create a file named script.sh
with the following code:
#!/bin/bash
echo $MY_ENV_VAR
If you run the following command, the terminal displays Terminal session
:
MY_ENV_VAR='Terminal session' sh ./script.sh
If you set the custom environment variable by using multiple approaches described in this topic, then when you try to get the custom environment variable's value, this setting takes priority over all of the others.
Set Custom User Environment Variables in ~/.bash_profile
You can set custom user environment variables in the ~/.bash_profile
file in your environment. To test this behavior, add the following code to the ~/.bash_profile
file in your environment:
export MY_ENV_VAR='.bash_profile file'
If you then run sh ./script.sh
from the command line, the terminal displays
.bash_profile file
. (This assumes you created the
script.sh
file as described earlier.)
Set Local Custom Environment Variables
You can set local custom environment variables in a terminal session by running the
export
command. To test this behavior, run the following command in a terminal session:
export MY_ENV_VAR='Command line export'
If you then run sh ./script.sh
from the command line, the terminal displays
Command line export
. (This assumes you created the script.sh
file as
described earlier.)
If you set the same custom environment variable with the
export
command and in your ~/.bash_profile
file, then when you
try to get the custom environment variable's value, the
export
command setting takes priority.
Set Custom User Environment Variables in ~/.bashrc
You can set custom user environment variables in the ~/.bashrc
file in your environment. To test this behavior, add the following code to the ~/.bashrc
file in your environment:
export MY_ENV_VAR='.bashrc file'
If you then run sh ./script.sh
from the command line, the terminal displays
.bashrc file
. (This assumes you created the script.sh
file as described earlier.)
If you set the same custom environment variable with the
export
command and in your ~/.bashrc
file, then when you try to get the custom environment variable's value,
the
export
command setting takes priority.
Set Custom Environment Variables in the ENV List
You can set custom environment variables in the ENV list on the Run tab.
To test this behavior, do the following:
-
On the menu bar, choose Run, Run Configurations, New Run Configuration.
-
On the [New] - Idle tab, Choose Runner: Auto, and then choose Shell script.
-
Choose ENV, and then type
MY_ENV_VAR
for Name andENV list
for Value. -
For Command, type
./script.sh
. -
Choose the Run button. the runner tab displays
ENV list
. (This assumes you created thescript.sh
file as described earlier.)
If you set the same custom environment variable in your ~/.bash_profile
file, with the
export
command, in your ~/.bashrc
file, and in the ENV list,
then when you try to get the custom environment variable's value, the
~/.bash_profile
file setting takes first priority, followed by the
export
command setting, the ~/.bashrc
file setting, and the ENV list setting.
Note
The ENV list is the only approach for getting and setting custom environment variables by using code, separate from a shell script.