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

Long Running Tasks

Overview

AWS Lambda maximum execution duration per request is 15 minutes, hence it is impossible to utilise a Lambda to execute a long-running task. batch handles your batch processing needs by providing a beautifully designed API which abstracts the time limitation problem.

These are the currently supported input sources:

  • DynamoDB
  • S3

How it works internally

batch works around the Lambda's time limitation by using recursion. It will automatically recurse when Lambda timeout is about to happen, then resumes from where it left off in the new invocation.

Imagine if you are about to process the array [1, 2, 3, 4, 5] and each request can only handle two items, the following will happen:

  • request 1: Process 1
  • request 1: Process 2
  • request 1: Not enough time, recursing with the current cursor
  • request 2: Process 3
  • request 2: Process 4
  • request 2: Not enough time, recursing with the current cursor
  • request 3: Process 5

Using built-in readers

The Laconia batch processor can be used by creating the laconiaBatch handler. The handler will require a reader, which is responsible on providing the next item available from the input source. Once you have set the reader up, the handler will fire item event which would contain the item that has been read by the reader specified.

const laconiaBatch = require("@laconia/batch");

const instances = () => ({ service: new MyService() });

exports.handler = laconiaBatch(_ =>
  // Create S3 Reader
  laconiaBatch.s3({
    path: ".",
    s3Params: {
      Bucket: process.env["BUCKET_NAME"],
      Key: "items.json"
    }
  })
)
  .register(instances)
  .on("item", async ({ service }, item) => {
    // Process the item found in the array in items.json
    service.operate(item);
  });
← Invoking Other LambdasCreating Middleware →
  • Overview
  • How it works internally
  • Using built-in readers
Laconia
Docs
Getting StartedCore ConceptsAPI Reference
Community
Stack OverflowChat
More
TwitterGitHubStar
Copyright © 2022 Wisen Tanasa
Logo designed by Suzie Nam