Simple package to allow versioning in AWS Lambdas as well as basic fallback.
There is no tagging in AWS Lambdas which makes it difficult to have multiple versions of a Lambda running. Think of backwards compatibility with some clients. Also, in the case of a Lambda going down in one AZ you have the ability to call other AZ's until one runs.
var LambdaRouter = require('lambda-runtime');
var lambda = new LambdaRouter(awsKey, awsSecret);
var supportedLambdas = {
"2015-02-01": "0.0.*",
"2016-09-01": "1.3.*"
};
var version = supportedLambdas[obj.version];
var lambdaName = "magic";
var env = process.env.NODE_ENV;
var payload = JSON.stringify({});
lambda.invokeAsync(lambdaName, env, version, ['us-east-1', 'us-west-2'], payload, function(err, data) {
console.log(err, data);
});
For the package to perform its function effectively, your lambda names must follow this guideline:
NAME-WITH-WHATEVER-SIZE-YOU-NEED-IT-**ENV**-**MAJOR**-**MINOR**-**PATCH**
Returns a LambdaRuntime object.
Function used to compare against official Lambdas
lambda
- Object must have FunctionName defined.functionName
- Name to be compared with FunctionNameenv
- Env to be compared with FunctionNameversion
- Version to be comprared with FunctionName
Returns true if the Lambda is compatible with the one being compared with.
lambdas
- Array of Lambda names. Ex -> ['name-production-0-2-1', 'name-production-0-1-2'];
Returns the latest definition of the Lambda.
functionName
- Lambda name to look for.env
- Env to look for.version
- Semantic version that should be matched Ex -> (^0.0.x)region
- Region to look for.callback(err, lambda)
- Will be called with the latest version found.
lambdas
- Array of lambdas. Ex -> [null, {name: name-production-0-1-2, region: us-west-2}, {name: name-production-0-1-1, region: us-east-1}]payload
- Payload to be invoked.callback(err, result)
- If no Errors happened, result can befalse
or a Lambda object. False implies that no Lambda was accepted.
Once 1 Lambda is successfully executed, the callback will be triggered.
name
- Name of lambda.env
- Env of lambda.version
- Semantic version to compare against.payload
- Payload for lambda.callback(err, lambda)
- If no Errors happened, result can befalse
or a Lambda object. False implies that no Lambda was accepted.