Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 566
Max Vinogradov Avatar asked Jan 28 '18 21:01

Max Vinogradov


People also ask

Can Lambda layer access environment variables?

You are right that there is no concept of environment variables for Lambda Layers.

How do I use AWS SDK in Lambda node?

To integrate the latest version of an AWS SDK into your Lambda function's deployment package, create a Lambda layer, and then add it to your function. You can use either the AWS Command Line Interface (AWS CLI) or the Lambda console to create a Lambda layer and add it to your function.

Where are AWS environment variables stored?

To set environment variables Sign in to the AWS Management Console and open the Amplify console . In the Amplify console, choose App Settings, and then choose Environment variables. In the Environment variables section, choose Manage variables. In the Manage variables section, under Variable, enter your key.

Is AWS SDK available in Lambda?

The Lambda service also provides AWS SDKs for your chosen runtime.


2 Answers

Just as you would any environment variable from node

const tableName = process.env.TABLE_NAME; 
like image 117
Richie Mackay Avatar answered Sep 19 '22 13:09

Richie Mackay


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

like image 26
kumarras Avatar answered Sep 19 '22 13:09

kumarras