I have a simple Java web application deployed on AWS Elastic Beanstalk as a self-contained JAR file. It pulls values from environment variables to display them in web pages as HTML. Simplifying the application a bit, if I assign the environment variable PAGE_TEST = "foo\nbar", then when I go to the page /test then I will see the following, because my application parses out the lines into paragraphs
…
<p>foo</p>
<p>bar</p>
…
The first problem is that in Elastic Beanstalk, setting the environment variable PAGE_TEST to foo\nbar doesn't work! On the test page I get this:
…
<p>foonbar</p>
…
Apparently AWS Elastic Beanstalk is trying to interpret my backslash characters. Why? How can I turn this off? I want it just to use the exact values I give it! Who told it to try to evaluate the values as escape codes?
I can work around this by escaping the backslash as foo\\nbar, but I shouldn't have to!
But now there is a worse problem. I set the environment variable PAGE_TEST to dança, which is a perfectly legitimate Unicode string—the Portuguese word for "dance". Unfortunately Elastic Beanstalk passes dan?a to my application.
…
<p>dan?a</p>
…
From experience I might guess that Elastic Beanstalk is trying to interpret the value as ASCII, and it is using a charset decoder that simply substitutes any non-ASCII character with ?. Or something. By why would it do that? It's 2020—what's wrong with just using Unicode?
Can someone help me tell AWS Elastic Beanstalk to stop mucking around with my perfectly valid environment variables and simply accept them as I provide them? I would be grateful.
I found some Elastic Beanstalk configuration documentation saying that environment variables can only use values with the characters _ . : / = + \ - @ ' ". Sheesh! And it didn't even alert me to the problem during validation of the settings, and instead just blithely replaced characters it didn't like with ?.
I still don't know why it considers the \ character an escape character and removes it.
In any case this completely breaks an application that was working fine locally. It looks like I'll have to redesign the functionality. Maybe I'll have to just Base64-encode the UTF-8 bytes of the string I want into the environment variable value. It seems so needless, though.
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