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

Adapting Events

Overview

Laconia provides two ways for you to adapt AWS events into your applications:

  • Creating your own adapter
  • Using Laconia built-in adapters

Creating an adapter

As Laconia is encouraging you to design your ports first, it is likely that you will need to implement your own adapter. Let's take a simple example of an S3 adapter that retrieves an S3 object from S3 bucket. You can do it like so with the event package:

const laconia = require("@laconia/core");
const { s3 } = require("@laconia/event");

const app = objectFromS3 => console.log(objectFromS3);

const adapter = app => async event => app(await s3(event).getObject());

exports.handler = laconia(adapter(app));

Using built-in adapters

Laconia also provides built-in adapters to handle simple adapter implementations. Only use the built-in adapters when it matches with your application's ports. Taking the previous example of retrieving an S3 object from S3 event, you can use the Laconia built-in adapters like this:

const laconia = require("@laconia/core");
const s3 = require("@laconia/adapter").s3();

const app = objectFromS3 => console.log(objectFromS3);

exports.handler = laconia(s3(app));

The adapter package is using the event package internally too.

← Unit TestingCreating API Endpoints →
  • Overview
  • Creating an adapter
  • Using built-in adapters
Laconia
Docs
Getting StartedCore ConceptsAPI Reference
Community
Stack OverflowChat
More
TwitterGitHubStar
Copyright © 2022 Wisen Tanasa
Logo designed by Suzie Nam