How get Environment Variables from lambda (nodejs aws-sdk)

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?


Solution 1:

Just as you would any environment variable from node

const tableName = process.env.TABLE_NAME;

Solution 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