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?
You are right that there is no concept of environment variables for Lambda Layers.
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.
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.
The Lambda service also provides AWS SDKs for your chosen runtime.
Just as you would any environment variable from node
const tableName = process.env.TABLE_NAME;
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.
You can fetch the above using
let env = process.env.ENV_NAME
To read about it , you can refer the doc at AWS Doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With