Lambda Logger
This npm package enables nodejs to estimate the time it takes a call to a lambda function to return.
- Get the time immediately before calling a lambda function
- Get the time immediately after the call returns
- Log the differene to a Log group with a naming convention of
/metric/lambda/<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
var funcitonName = 'helloworld' + '-' + process.env.STAGE;
Update the Security template
- Give functions permission to:
- Create log group
- put cloudwatch metrics
Update the application template
Usage
var Lambda = require('lambda-logger');
exports.handler = (event, context, callback) => {
var lambda = new Lambda(context);
}
var request = {
FunctionName: 'Helloworld',
ProcessId: pid,
TranactionId: tid
};
lambda.invoke(request);
lambda.invoke(request)
.then((response) => {
return lambda.invoke();
})
.then(() => {
})
.catch((err) => {
});