@mineko/lambda-core v7.0.7
Lambda Core
Formerly know as lambda-basics which was a open-source project. This module provides a set of useful functions for lambda.
Install
npm i -S @mineko/lambda-core
peer dependency
This library needs tsyringe to work. tsyringe
is defined as peer dependency to prevent multiple DI containers (as every installation would get loaded).
Please take this into account when you setup your project's build process.
When your are using webpack to build your project:
Usage with webpack
Add following to your webpack.config.js
resolve: {
extensions: ['.js', '.ts', '.json'],
modules: [
path.join(__dirname, 'node_modules'), 'node_modules', //this line will first try to resolve dependencies in your projects node_modules folder
],
},
As well consider to use ts-loader:
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
},
],
},
Usage
For each class a instance is as well exported (except for LoggerInstance
as Logger
is defined in another project).
You can either use ready to use instances or use it in your own dependency framework.
LoggerInstance
See js-core for description.
Runtime / RuntimeInstance
Pass an lambda event and a callback to Runtime.execute(callback, event)
and it will automatically wrap it in a try catch
block and will check if it's a warm-up event.
It will call the callback injecting the event return callback(event)
and returning the callback result.
Usage
const handler = async (event) => {
return 'something';
}
exports.handler = async event => {
return RuntimeInstance.execute(handler, event);
}
SSMParameter / SSMParameterInstance
getValue(name)
Will return the value of an ssm parameter
ApiGatewayHeader / ApiGatewayHeaderInstance
get(event, headerKey)
: Will return the header value ofevent
for keyheaderKey
case insensitive
OAuth / OAuthInstance
getAccessToken(endpoint, clientId, clientSecret)
: Will return the response of anendpoint
to get an access token following OAuth client credentials flow
Validate / ValidateInstance
requestParams(requiredParams)(requestParams)
: Will return a function which will check ifparams
containsrequiredParams
ResponseHandler / ResponseHandlerInstance
getResponseObject(statusCode, headers, body)
: Will return a response object where the body is json stringgetErrorResponseBody(message, type)
: Wil lreturn a error response body
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago