2

I created a Nodejs Lambda function to use Environment variables based on: AWS Lambda Environment Variables - AWS Lambda

And I tried to access the environment with process.env but it does not work.

Here is my code:

exports.handler = async (event) => {
    console.log('The A varialbe is: ', process.env.A)
    console.log('\n')
    console.log('The all varialbes in process.env is: ', process.env)
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

You can see I already set a variable here:

enter image description here

But process.env.A return undefined and in process.env it does not contain my variable A

You can see actual result here:

enter image description here

6
  • Have you clicked the "save" button on the console after set the env var ? Commented Jun 27, 2019 at 6:00
  • @ChouW, I did it, I tried a lot of time but no success Commented Jun 27, 2019 at 6:00
  • Well... I think I found the root cause : your env var must satisfy regular expression [a-zA-Z]([a-zA-Z0-9_])+ Commented Jun 27, 2019 at 6:07
  • 4
    Try using AA instead A, it works for me. Commented Jun 27, 2019 at 6:07
  • Thank you a lot @ChouW, I got it worked, [a-zA-Z]([a-zA-Z0-9_])+ where you find it, I can not find it in docs. Commented Jun 27, 2019 at 6:38

1 Answer 1

4

I create the Lambda you described above, and got the error from the console.

your env var must satisfy regular expression [a-zA-Z]([a-zA-Z0-9_])+

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

the next time, I think I should disable some block ads extensions, I can not see the error, thank you a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.