Home > Back-end >  How AWS Lambda functions get the dependencies during execution
How AWS Lambda functions get the dependencies during execution

Time:05-01

I have just started learning AWS and nodejs . I am trying to understand how this lambda in the serverless app gets the required information while execution .Let's consider the below piece of code

use strict';

var AWS = require("aws-sdk");

var lambda = new AWS.Lambda({
    apiVersion: '2015-03-31',
    endpoint: 'https://lambda.'   process.env.DYNAMODB_REGION   '.amazonaws.com',
    logger: console
});

So the first statement it creates a variable AWS . In any normal application these dependencies will be available in node modules and when we refer to it , we will easily access it . But here in the case of lambda function which has been created as a serverless app how it gets the dependency.

My second question is when we refer to process.env.DYNAMODB_REGION what would be the value for process.env ?

My third question is it possible to create a common logger file, get it imported inside the lambda and use it to log the details ?

Please help me to understand how lambda function get all these details .

CodePudding user response:

  1. the aws-sdk dependency is provided by the Lambda runtime, so you don't have to download and package it yourself. Any other dependency that's not provided by the runtime, you will have to package them in the zip file which you upload when creating your Lambda function.

  2. DYNAMODB_REGION is not a standard environment variable that's set by the runtime; you'd have to provide its value yourself when you create your lambda. For the list of environment variables that are set by the Lambda runtime, as well as how to set your own environment variables, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html.

  3. Not exactly sure what you are asking, but for logging, the easiest way is to use AWS CloudWatch. For more information you can see https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html.

The code you posted is accessing a lambda function within another lambda function. It is not exactly how you'd create your lambda function for your serverless app.

  • Related