I'm getting shellcheck suggestion SC2806 i.e. Double quote to prevent globbing and word splitting for $JAVA_OPTS.
When I apply that to my code
java $JAVA_OPTS -Dhttps.proxyHost=%PROXY_HOST%
I get the 503 Error Back-end server busy error. The ec2 instance activity reports that the instance health check failed.
But when I don't use "" to $JAVA_OPTS, then it works and I get 200 OK response and everything works.
when I echoed $JAVA_OPTS it echoed as empty.
What could be the reason for this?
The other answer explains what causes the issue.
Here’s how to fix it: instead of passing $JAVA_OPTS (either quoted or unquoted) to java, pass ${JAVA_OPTS:+"$JAVA_OPTS"}. This will cause the parameter expansion only if it is non-empty. If $JAVA_OPTS is empty, no expansion will be passed to the command.
See the documentation for more information about the :+ expansion.