serverless-toolkit
A collection of useful functions for serverless development.
Installation:
npm
npm install --save serverless-toolkit
yarn
yarn add serverless-toolkit
Error Mailer
When a function errors, receive the error via email. This is first tries to send the email via Amazon SES. If that fails it will fallback to sendmail.
Usage:
// Returns the return value of functionToWatch. If functionToWatch throws an error this will return a Promise.// If errorHandler is supplied, it will be called once the error email has been sent and the promise will be resolved with the// return value of errorHandler; // alternatively you can read the environment variables of your function.// receiverEmail defaults to process.env.ERROR_RECEIVER_EMAIL and senderEmail defaults to process.env.ERROR_SENDER_EMAIL;
Example usage:
const errorMailer = errorMailer; { throw "This failed."} // this function will be called once the error email has been sent with the same arguments { return Promise} // Remember to update receiver and sender since @example.com will often get filtered to spamvar protected = protected"firstArg" "secondArg"
Example email:
An execution error occured!
Function: iWillFail
Error: This failed.
Arguments: firstArg, secondArg
Error: This failed.
at iWillFail (/Users/example/sample/test.js:4:9)
at replacement (/Users/example/sample/node_modules/serverless-toolkit/errorMailer/index.js:45:22)
at Object. (/Users/example/sample/test.js:9:1)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11
"This is a test"
Dropbox storage
This is a library to easily store data in your dropbox account.
Initialization
// accessToken can also be read from "process.env.DROPBOX_TOKEN"StorageaccessToken
Reading Files
async async async async async // To Filesystemasync
Writing Files
async // will use the dirname of the filePath / directoryPathasync async async // appends a single object and checks that the object has the same keys as the remote csv, otherwise an error is thrown // From URL// Supply headers via the customHeaders parameter like // { "Authorization": "Bearer abc" }async // From Filesystemasync // this will merge two csv files based on a primaryKey (or the whole row if primaryKey is undefined or not found in the input)async
Sample usage:
const { Storage } = require('serverless-toolkit')
let storage = new Storage()
let obj = await storage.getCsvAsObject("/test.csv")
Log Writer
Outputs function results to a specified file in Dropbox
;
Sample usage:
{ return 42;} const newFunction =