Lambda Timer
-
Adds pre and post hooks to a lamdba function so that we can generate duration data, and simplify the output of a single lambda call into a single log entry
with a unified format
-
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
var funcitonName = 'helloworld' + '-' + process.env.STAGE;
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)
.then((response) => {
var request = {
FunctionName: 'Goodbyeworld',
ProcessId: pid,
TranactionId: tid
};
return lambda.invoke(request);
})
.then(() => {
})
.catch((err) => {
});
}
TODO:
- Update the Security template give functions permission to:
- Create log group
- put cloudwatch metrics
- Update the application template
- test promise chaining
- implement callback version