55

We can set up Environment Variables in aws-lambda for example via AWS SAM:

Environment:
    Variables:
      TABLE_NAME: !Ref Table

How can I get this variables from current lambda via Node JS AWS-SDK?

2 Answers 2

105

Just as you would any environment variable from node

const tableName = process.env.TABLE_NAME;
Sign up to request clarification or add additional context in comments.

2 Comments

require('process') isn't necessary. Just process.env.TABLE_NAME will work as process.env is set globally in node.
Thanks point well made and I have updated the answer. Here is a reference in the documentation nodejs.org/api/process.html#process_process
4

I am just adding to the original answer to clarify the scope.To fetch any environment variable whether is defined by API or manually, you can use process.env.ENV_NAME

E.g. Environment variable declaration in console

You can fetch the above using

let env = process.env.ENV_NAME

To read about it , you can refer the doc at AWS Doc

Comments

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.