This npm package logs data about calls to lambda functions including:
Duration
Request/ Response objects
Log the duration of a call from <caller-name> to <invoked-name> to a Log group with a naming convention of /metric/lambda/correlation/<caller-name>/<invoked-name>
When using serverless
Serverless automatically appends the stage variable to lambda functions when deploying to aws
It is suggested you add the stage variable as an environment variable for your lamdba functions. This allows you to dynamically piece together the correct funciton name for the stage being tested
// Initialize lambda loggervarLambda=require('lambda-logger');exports.handler=(event,context,callback)=>{// Pass the context object to lambda wrappervarlambda=newLambda(context);// Invoke functionvarrequest={FunctionName: 'Helloworld',ProcessId: pid,TranactionId: tid};lambda.invoke(request).then((response)=>{// Do work ...// Chaining callsvarrequest={FunctionName: 'Goodbyeworld',ProcessId: pid,TranactionId: tid};returnlambda.invoke(request);}).then(()=>{// Do final steps}).catch((err)=>{// Error within promsise chain});}
TODO:
Update the Security template give functions permission to: