This package has been deprecated

Author message:

This package has been replaced with @corva/node-sdk

@corva/node-generic-lambda
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

node-generic-lambda

Generic lambda class for constructing data apps. It provides base class to build more specific lambdas. This package defines general workflow

ToC

Requirements

  • node.js - >=12.0.0

Getting started

Installation

npm i @corva/node-generic-lambda

Features

  • Defines generic workflow
  • Logs errors

Workflow

Generic lambda has 3 phases:

  • pre-process
  • process
  • post-process
@startuml
(*) -->[{event}] "preProcess"

if "Exception?" then
  -->[true, {error}] "postProcess"
else
  -->[false, {event}] "process"
  -->[{data, error}] "postProcess"
endif
-->[End] (*)
@enduml

workflow diagram

Usually you need to define process function to handle the data. Pre-process is used to modify incoming data in some way. Post-process is used to handle processed data or/and handle and log errors that were thrown during pre-process or process.

Also it expose .run method that is used to launch processing.

Usage

@startuml
GenericLambda <|-- StreamLambda
GenericLambda <|-- ScheduledLambda
GenericLambda <|-- TaskLambda

class GenericLambda {
  {static} Error LambdaError
  {abstract} process({event, context})
  #preProcess({event, context})
  #postProcess({event, context, data, error})
  #run({event,context})
}

class StreamLambda {
  {abstract} process({event, context})
  #preProcess({event, context})
  #postProcess({event, context, data, error})
}

class ScheduledLambda {
  {abstract} process({event, context})
  #preProcess({event, context})
  #postProcess({event, context, data, error})
}

class TaskLambda {
  {abstract} process({event, context})
  #preProcess({event, context})
  #postProcess({event, context, data, error})
}

@enduml

usage diagram

Examples

const { GenericLambda } = require('@corva/node-generic-lambda');

class MyLambda extends GenericLambda {
  constructor({ customOptions, ...options }) {
    super(options);
    this.foo = customOptions.foo;
  }

  async preProcess({ event, context }) {
    await super.preProcess({ event, context });
    // you can modify event
    event.foo = this.foo;
    // and return it, so it will be passed to processor function instead of original
    return event;
    // or return undefined if you want to pass original event
  }

  async postProcess({ event, context, data, error }) {
    await super.postProcess({ event, context });
    if (error) {
      // handle error
      return;
    }
    // do something with data
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @corva/node-generic-lambda

Weekly Downloads

1

Version

5.0.0

License

UNLICENSED

Unpacked Size

426 kB

Total Files

11

Last publish

Collaborators

  • aj8k
  • leonid.khomenko
  • suchov
  • vasyl.skalozub
  • andrii.koval
  • yuliiahryhorchuk
  • mgdskr_corva
  • ruslan.shukiurov
  • maksymozymok
  • kostia.khozhay
  • ryandawson
  • bestfit
  • oleksandr_krupko
  • villeti
  • jordanambra
  • dumavit1
  • antonpyrlyk
  • corva-devops-automation