50

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?

Max Vinogradov
  • 1,343
  • 1
  • 13
  • 31

2 Answers2

96

Just as you would any environment variable from node

const tableName = process.env.TABLE_NAME;
Richie Mackay
  • 1,385
  • 10
  • 12
  • 4
    require('process') isn't necessary. Just process.env.TABLE_NAME will work as process.env is set globally in node. – Usman Mutawakil Jan 30 '18 at 03:59
  • 1
    Thanks point well made and I have updated the answer. Here is a reference in the documentation https://nodejs.org/api/process.html#process_process – Richie Mackay Jan 30 '18 at 08:46
2

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.VAR_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

kumarras
  • 116
  • 5