0

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.

AWS has a blog post here that shows the above process for setting environment variables. See the section "Conversion to environmental variables".

Is there something I'm not doing to make this work for a Lambda handler?

rpivovar
  • 3,150
  • 13
  • 41
  • 79
  • 1
    I don't think this approach is going to work. See: https://stackoverflow.com/questions/66252692/finding-an-equivalent-of-environment-variables-in-aws-lambda-layers – jarmod Feb 01 '22 at 18:35

0 Answers0