Laconia

Laconia

  • Getting Started
  • API
  • Help

›API Reference

Introduction

  • Getting Started
  • Motivation
  • Core Concepts
  • Philosophy
  • Examples
  • FAQ
  • Support Me

Laconia vs. Other

  • Claudia
  • Express, Koa, Hapi, etc.
  • Middy
  • Serverless, SAM, Apex, etc.

Guides

  • Injecting Dependencies
  • Unit Testing
  • Adapting Events
  • Creating API Endpoints
  • Retrieving Secrets
  • Retrieving Config
  • Warming Up
  • Invoking Other Lambdas
  • Long Running Tasks
  • Creating Middleware

API Reference

  • API Reference: Intro
  • core
  • event
  • adapter
  • adapter-api
  • invoker
  • config
  • batch
  • middleware-lambda-warmer
  • middleware-serverless-plugin-warmup
Edit

core

laconia(app(event, laconiaContext))

Creates a new Laconia handler that can be called by AWS Lambda.

  • app(event, laconiaContext)
    • This Function is called when your Lambda is invoked
    • Will be called with laconiaContext object, which can be destructured to retrieve your dependencies

Example:

// Simple return value
laconia(() => "value");

// Return a promise and 'value' will be returned to the Lambda caller
laconia(() => Promise.resolve("value"));

// Destructure laconiaContext
laconia((event, { dependency }) => dependency(event));

// Retrieve AWS context and raw event from LaconiaContext
// (when an adapter is used, the first parameter is not an event anymore)
laconia((_, { event, context }) => console.log(event, context));

register(factory(laconiaContext), options)

Registers objects created by the factory function into LaconiaContext. Objects registered here will be made available in the Lambda function execution. You can pass an array for the list of array to be called in parallel.

  • factory(laconiaContext)
    • This Function is called when your Lambda is invoked
    • When an Array is specified, the list of factories within the array will be called concurrently with Promise.all
    • An object which contains the instances to be registered must be returned
  • options:
    • cache
      • enabled = true
        • Set to false to turn off caching
      • maxAge = 300000
        • Your factory will be called when the cache has reached its maximum age specified by this option

Example:

// Register an object with key 'service'
laconia((event, { service }) => service.call()).register(() => ({
  service: new SomeService()
}));

// Register concurrent factories
const app = () => {};
laconia(app).register([config.envVarInstances(), invoker.envVarInstances()]);

// Using laconiaContext in factory
const app = () => {};
laconia(app)
  .register(() => ({ secret: sharedLibToGetSecret() }))
  .register(({ secret }) => ({ service: new SomeClient(secret) }));

// Reduce cache maxAge
const app = () => {};
laconia(app).register(
  async () => ({
    /* heavy operations */
  }),
  {
    cache: {
      maxAge: 1000
    }
  }
);

// Turning caching off
const app = () => {};
laconia(app).register(() => {}, {
  cache: {
    enabled: false
  }
});

postProcessor(postProcessorFn(instances))

Upon Lambda runtime execution, every postProcessorFn will be called on every factory functions individually.

  • postProcessorFn(instances)
    • This Function is called when your Lambda is invoked

Example:

// Print object registered
laconia((event, { service }) => service.call())
  .register(() => ({
    service: new SomeService()
  }))
  .postProcessor(instances => console.log(instances));

// Enable xray
const xray = require("@laconia/xray");

laconia((event, { service }) => service.call())
  .register(() => ({
    service: new SomeService()
  }))
  .postProcessor(xray.postProcessor());
← API Reference: Introevent →
  • laconia(app(event, laconiaContext))
  • register(factory(laconiaContext), options)
  • postProcessor(postProcessorFn(instances))
Laconia
Docs
Getting StartedCore ConceptsAPI Reference
Community
Stack OverflowChat
More
TwitterGitHubStar
Copyright © 2022 Wisen Tanasa
Logo designed by Suzie Nam