Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an environment variable with a '$' in the value in Elastic Beanstalk?

When I enter a value that has a dollar sign $ the environment only reads the first part of it, and that's because the env file generated puts double quotes in the values instead of single quotes. Any way around that? The value can't be changed because it's an access token from a service I don't control.

Example:

The env file generated is like: export MY_VAR="my$value"

Running that results in: MY_VAR=my

like image 361
Diego Lorden Avatar asked Jun 03 '16 16:06

Diego Lorden


People also ask

Where are environment variables stored Elastic Beanstalk?

Environment properties are written to the /opt/python/current/env file, which is sourced into the virtualenv stack where the application runs. For more information, see Using the Elastic Beanstalk Python platform.

What are the two environments available in Elastic Beanstalk?

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.


2 Answers

Either escape the dollar signs with three backslashes (works using either the web console or the command line):

eb setenv -e my-environment MY_VARIABLE=\\\$foobar

Or with a strong quotes ('') you would only have to use one backslash to escape:

eb setenv -e my-environment MY_VARIABLE='\$foobar'
like image 65
endrec Avatar answered Nov 08 '22 23:11

endrec


It is evaluating $value as a variable and converting it to an empty string since that variable doesn't exist in the environment. Try escaping the $ character like this:

export MY_VAR="my\$value"

Alternatively, use single quotes which should prevent variable expansion:

export MY_VAR='my$value'

like image 22
Mark B Avatar answered Nov 08 '22 22:11

Mark B