All Projects → juliantellez → Lambcycle

juliantellez / Lambcycle

Licence: mit
🐑🛵 A declarative lambda middleware with life cycle hooks 🐑🛵

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Lambcycle

Aws Lambda List
A list of hopefully useful AWS lambdas and lambda-related resources.
Stars: ✭ 130 (+47.73%)
Mutual labels:  aws, serverless, aws-lambda, lambda, lambda-functions
Webiny Js
Enterprise open-source serverless CMS. Includes a headless CMS, page builder, form builder and file manager. Easy to customize and expand. Deploys to AWS.
Stars: ✭ 4,869 (+5432.95%)
Mutual labels:  aws, serverless, aws-lambda, lambda, lambda-functions
Aws Serverless Airline Booking
Airline Booking is a sample web application that provides Flight Search, Flight Payment, Flight Booking and Loyalty points including end-to-end testing, GraphQL and CI/CD. This web application was the theme of Build on Serverless Season 2 on AWS Twitch running from April 24th until end of August in 2019.
Stars: ✭ 1,290 (+1365.91%)
Mutual labels:  aws, serverless, aws-lambda, lambda, lambda-functions
Grant
OAuth Proxy
Stars: ✭ 3,509 (+3887.5%)
Mutual labels:  aws, serverless, aws-lambda, lambda, middleware
Serverless Plugin Warmup
Keep your lambdas warm during winter. ♨
Stars: ✭ 814 (+825%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Archive aws Lambda Go Shim
Author your AWS Lambda functions in Go, effectively.
Stars: ✭ 799 (+807.95%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Serverless Node Simple Image Resize
Simple image resize AWS lambda function
Stars: ✭ 74 (-15.91%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Serverless Node Simple Messaging
Simple email AWS lambda function
Stars: ✭ 75 (-14.77%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (+439.77%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Aws Lambda Workshop
Some incremental examples suitable to host an AWS Lambda Functions workshop
Stars: ✭ 18 (-79.55%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Lambda Refarch Webapp
The Web Application reference architecture is a general-purpose, event-driven, web application back-end that uses AWS Lambda, Amazon API Gateway for its business logic. It also uses Amazon DynamoDB as its database and Amazon Cognito for user management. All static content is hosted using AWS Amplify Console.
Stars: ✭ 1,208 (+1272.73%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Lambda Packages
Various popular python libraries, pre-compiled to be compatible with AWS Lambda
Stars: ✭ 713 (+710.23%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Archive aws Lambda Go
A fast and clean way to execute Go on AWS Lambda.
Stars: ✭ 710 (+706.82%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Lambdalogs
A CLI tool to trace AWS Lambda calls over multiple CloudWatch log groups.
Stars: ✭ 18 (-79.55%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Serverless Plugin Stackstorm
Plugin for serverless framework to run ready to use actions from StackStorm Exchange as AWS Lambda.
Stars: ✭ 28 (-68.18%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Chalice
Python Serverless Microframework for AWS
Stars: ✭ 8,513 (+9573.86%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Epsagon Go
Automated tracing library for Go 1.x ⚡️
Stars: ✭ 24 (-72.73%)
Mutual labels:  serverless, aws-lambda, lambda, lambda-functions
Apex
Old apex/apex
Stars: ✭ 20 (-77.27%)
Mutual labels:  aws, serverless, aws-lambda, lambda
Serverless Photo Recognition
A collection of 3 lambda functions that are invoked by Amazon S3 or Amazon API Gateway to analyze uploaded images with Amazon Rekognition and save picture labels to ElasticSearch (written in Kotlin)
Stars: ✭ 345 (+292.05%)
Mutual labels:  aws, serverless, aws-lambda, lambda-functions
Serverless Rust
⚡ 🦀 a serverless framework plugin for rustlang applications
Stars: ✭ 386 (+338.64%)
Mutual labels:  aws, serverless, aws-lambda, lambda

lambcycle

Lambcycle is a declarative lambda middleware. Its main purpose is to let you focus on the specifics of your application by providing a configuration cycle.

🐑🛵 Read the introductory blog post here 🐑🛵.

Known Vulnerabilities Serverless MIT License FOSSA Status

Install

# with npm
npm install --save lambcycle

# with yarn
yarn add lambcycle

Introduction

Lambcycle is a middleware for lambda functions. It defines a configurable life-cycle and allows you to focus on your application's logic. It has a "Feature as Plugin" approach, so you can easily create your own plugins or reuse your favorite packages with very little effort 🐑 🛵.

Checkout the following example or follow the link to 🎉 see some actual code 🎉 .

// with es6

import Joi from "joi";
import lambcycle from "lambcycle";

import pinoPlugin from './myPinoPlugin'
import joiPlugin from './myJoiPlugin'
import bodyParserPlugin from './myBodyParserPlugin'

import applicationLogic from "./mycode";

const processData = async (event, context) => {
  // beautiful application logic ...

  const manipulateData = event => {
    // ...
  };

  return await applicationLogic(manipulateData(event), context);
};

const schema = Joi.object()
  .keys({
    username: Joi.string().alphanum().min(5).required(),
    password: Joi.string().regex(/^[a-zA-Z0-9]{5,30}$/),
    email: Joi.string().email({ minDomainAtoms: 2 })
  });

const handler = lambcycle(processData).register([
  pinoPlugin,
  bodyParserPlugin,
  joiPlugin(schema)
]);

export default handler;

Handler lifecycle

The lifecycle provides a clear guideline to reason about your needs. Every step of the cycle can handle or throw errors making it easy to log, report or debug.

Lambcycle enhances lambda functions with a few extension points (see graph), each of which can be used to interact with the event in a decomposed manner.

  • The first extension point is Request which occurs immediately after the lambda is called. You can use this step for parsing, validation, etc... Note: If you are thinking of auth, please consider a lambda authoriser instead.

  • The Pre Handler extension comes in handy when you need to adapt data to fit an interface. It is also a great place for fetching secrets.

  • The Handler, where your beautiful business logic lives.

  • Next up is the Post Handler, use this extension to validate and/or cache the output of your business logic.

  • Error is an implicit extension for logging and tracing.

  • And finally Pre Response, your chance to format a response to the consumer (which could be data or an error).

Error Handling

The error object is a first class citizen that will stop the cycle and execute any error plugins declared in the register, it will then proceed to call the lambda handler's callback. Have a look at the Wrapper Interface to see what's available for reporting.

HINT: pretty much everything.

import lambcycle from 'lambcycle'
import notifyError from './myErrorNofifier'

const appLogic = async(event, context) => {
    const {error, data} = await amazingJob()
    if(error) {
        throw error
    }
}

const errorNotifier = {
    plugin: {
        onError: async (handler) => {
            /**
             * See IWrapper interface
            */
            await notifyError(handler.error)
        }
    }
}

const handler = lambcycle(appLogic).register([errorNotifier])

export default handler;

Plugins

  • BodyParser: Parse incoming request bodies before your handler, available under the handler.event.body property.
  • Joi: Object schema description language and validator for JavaScript objects. Validate requests without the pain!

Creating a plugin

A plugin is an object that can attach its hooks to one or more event cycles, it may provide its own configuration object.

type IPluginHookFunction = (
    wrapper: IWrapper,
    config: object,
    handleError?: Callback
) => void;
import * as Sentry from '@sentry/node';
import MyAwesomeIntegration from './MyAwesomeIntegration'

const sentryPlugin = (config) => {
    Sentry.init({
        dsn: `https://[email protected]/${config.project}`,
        integrations: [new MyAwesomeIntegration()]
    });

    return {
        config,
        plugin: {
            onPreResponse: async (handlerWrapper, config) => {
                Sentry.captureMessage('some percentile log perhaps?')
            },
            onError: async (handlerWrapper, config) => {
                Sentry.captureException(handlerWrapper.error);
            }
        }
    }
}

export default sentryPlugin;

Using a plugin

Let's reuse the example above. Make sure your lambdas follow the Principle of least privilege and your secrets stay SECRET ㊙️

import lambcycle from 'lambcycle'
import sentryPlugin from './sentryPlugin'

const myApplicationLogic = async (event, context) => {
    await someLogic()
}

const handler = lambcycle(myApplicationLogic)
.register([
    sentryPlugin({
        key: process.env.SENTRY_KEY,
        project: process.env.SENTRY_PROJECT,
    })
]);

export default handler;

DevX

Lambcycle ships with type definitions, making the dev experience smoother 🚀 (VScode only).

typeintellisense

About the project

This project has been built with lots of ❤️ and Typescript 🤣. It embraces the middleware pattern and uses types for consistency and documentation. If this approach seems familiar to you is because it was inspired by the awesome hapijs.

Contributing

As you can see the possibilities are endless when it comes to plugins! Everyone is welcome to contribute! Feel free to create issues or prs.

License

MIT License

FOSSA Status
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].