Code Monkey home page Code Monkey logo

serverless-plugin-flambe's Introduction

npm downloads total npm version npm license

Installation

npm install serverless-plugin-flambe --save-dev

or

yarn add serverless-plugin-flambe --dev

Usage

In the serverless file, add serverless-plugin-flambe within the plugins entry.

Example:

functions:
  hello:
    handler: src/hello.handler
    timeout: 15

plugins:
  - serverless-plugin-flambe

By default all functions will then be automatically scheduled, wrapped to accept scheduled events, and immediately invoked post-deployment. If you want more granular control, options can be configured within a custom flambe variable.

Custom Declaration

In case your project doesn't require all of your lambdas to be warm, you can list the name of a specific lambda or use regular expressions declared in the custom level variables.

Example:

custom:
  flambe:
    regex:
      - hello
      - /good.*/
    memorySize: 512
    rate: rate(5 minutes)

The above example will keep the function hello warm as well as functions prefixed with the name good. If there are no lambdas that match in the declared list, nothing will be scheduled.

Lambda Configuration

In order to fine-tune the rate, input, and flow of your code, lambdas are configured on a per-lambda basis using the field flambe

Option Values Default Description
rate AWS rate 5 minutes How often the lambda is to be called
wrapper String null The file path where a custom wrapper exists (same as a function handler definition)
input Object { flambe: true } The event the lambda receives, when it is pinged

Options Example

functions:
  hello:
    handler: handlers.hello
    timeout: 10
    flambe: 
      rate: 'rate(3 minutes)'
      
  goodbye:
    handler: handlers.goodbye
    flambe:
      wrapper: wrapper.logger
      input:
        custom: 'property'

Custom Wrapper(s)

If you want to build a custom wrapper instead of the default flambe wrapper, it needs to be written as a higher-order-function.

Example:

// wrappers.js
const logger = (original) => (evt, ctx, cb) => {
  console.log('Logging event data:', JSON.stringify(evt, null, 2));
  return original(evt, ctx, cb);
}

module.exports = {
  logger,
};

Plugin Conflicts

Make sure serverless-plugin-flambe is placed before any plugins that compile code. Example:

plugins:
  - serverless-plugin-flambe
  - serverless-webpack

Cost

Cost per execution: $0.0000002

Cost per memory allocated 1024MB: $0.000001667

Calls per day: 288

Calls per month: 8640

Total monthly cost per-lambda: $0.016

**Prices calculated using the following aws information here.

Changelog

0.1.5

  • Flambe log retention now uses the value set in the provider

0.1.4

  • Fixed a misspelling that was preventing options stage from being resolved

0.1.3

  • Default to options stage, region instead of provider

0.1.2

  • Re-enabled cleanup phase post local invocation

0.1.1

  • PATCH: Using relative paths for original handlers instead of copying the source

0.1.0

  • Changed how flambe custom options are defined
  • Decrease memorySize of generated function to 128 MB
  • Using Serverless lambda invocation instead of custom

serverless-plugin-flambe's People

Contributors

icarus-sullivan avatar

Watchers

 avatar

serverless-plugin-flambe's Issues

Set flambe function memory to 128 MB

Currently the flambe lambda gets deployed with the project's memorySize that is defined in the serverless.yml file.

However, some projects may use higher default memory sizes for their lambdas.

Since the flambe lambda just invokes the other lambdas, it has a very small memory requirement and should have a small default memorySize, like 128 MB.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.