I'm trying to set environment variables from inside a Lambda wrapper script contained in a Lambda layer (I can do this more directly elsewhere, but I'm trying to set them from a wrapper script for specific scenarios).
Here's the important parts of the wrapper script:
set -euo pipefail
OWN_FILENAME="$(basename $0)"
tempFile=$(mktemp /tmp/${OWN_FILENAME}.XXXXXXXX)
echo "export ONE=\"two\"" >> ${tempFile}
. ${tempFile}
Here, I'm creating a temporary file which contains an environment variable exported to the environment. Then I source the file.
I would expect this to create a variable called ONE
on process.env
, which is set to "two"
.
If I were to run this script and then run a Node script that contains:
console.log(process.env.ONE);
It would print "two"
.
However, this appears to not work with a NodeJS Lambda. I can see that, if I add logs to the wrapper script, the logs will print prior to the Lambda handler running, so it appears the wrapper script is definitely executing prior to the handler.
Is there something I'm not doing to make this work for a Lambda handler?