Laconia

Laconia

  • Getting Started
  • API
  • Help

›Guides

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

Invoking Other Lambdas

Overview

Invoking other Lambdas is a common pattern in serverless architecture. Laconia makes this easy by:

  • Automatically stringifying JSON request payload and parsing JSON response payload
  • Throwing an error when FunctionError is returned instead of failing silently
  • Augmenting stacktrace in the FunctionError thrown based on the stacktrace returned by Lambda invocation
  • Set the FunctionError object's name and message thrown based on the error returned by Lambda invocation
  • Throwing an error when statusCode returned is not a success code

Guide

Lambda invocation is Laconia is handled by an instance of invoker. Create an invoker and invoke your Lambda through it like so:

/**
 * Lambda Environment variables:
 * - LACONIA_INVOKER_CALL_CAPTURE_CARD_PAYMENT_LAMBDA: capture-card-payment-lambda-name
 */

const invoker = require("@laconia/invoker");
const laconia = require("@laconia/core");

// By convention, the name of the variable `captureCardPaymentLambda` is derived by
// the environment variable name `LACONIA_INVOKER_CALL_CAPTURE_CARD_PAYMENT_LAMBDA`
const app = async (input, { captureCardPaymentLambda }) => {
  const parameter = { transactionId: 1 };
  // Waits for capture-card-payment-lambda-name
  const response = await captureCardPaymentLambda.requestResponse(parameter);
  console.log(response);
};

exports.handler = laconia(app).register(invoker.envVarInstances());

The invoker also supports Event invocation type (asynchronous Lambda execution), which can be called by replacing requestResponse with fireAndForget.

← Warming UpLong Running Tasks →
  • Overview
  • Guide
Laconia
Docs
Getting StartedCore ConceptsAPI Reference
Community
Stack OverflowChat
More
TwitterGitHubStar
Copyright © 2022 Wisen Tanasa
Logo designed by Suzie Nam