Skip to main content Link Search Menu Expand Document (external link)

LambdaHandler overview

Added in v1.4.0


Table of contents


constructors

fromHttpApi

Construct a lambda handler from an HttpApi instance.

Signature

export declare const fromHttpApi: <LA, LE>(
  layer: Layer.Layer<LA | HttpApi.Api | HttpRouter.HttpRouter.DefaultServices, LE>,
  options?: HttpApiOptions
) => Handler<LambdaHandler.Event, LambdaHandler.Result>

Example

import { LambdaHandler } from "@effect-aws/lambda"
import { HttpApi, HttpApiBuilder, HttpServer } from "@effect/platform"
import { Layer } from "effect"

class MyApi extends HttpApi.make("api") {}

const MyApiLive = HttpApiBuilder.api(MyApi)

export const handler = LambdaHandler.fromHttpApi(
  Layer.mergeAll(
    MyApiLive,
    // you could also use NodeHttpServer.layerContext, depending on your
    // server's platform
    HttpServer.layerContext
  )
)

Added in v1.4.0

httpApiHandler

Construct an EffectHandler from an HttpApi instance.

Signature

export declare const httpApiHandler: (
  options?: Pick<HttpApiOptions, "middleware">
) => EffectHandler<
  LambdaHandler.Event,
  HttpApi.Api | HttpApiBuilder.Router | HttpRouter.HttpRouter.DefaultServices | HttpApiBuilder.Middleware,
  Cause.UnknownException,
  LambdaHandler.Result
>

Added in v1.4.0

httpApiStreamHandler

Construct a streaming StreamifyHandler from an HttpApi instance for Lambda Function URLs.

Signature

export declare const httpApiStreamHandler: (
  options?: Pick<HttpApiOptions, "middleware">
) => EffectStreamifyHandler<
  LambdaHandler.Event,
  HttpApi.Api | HttpApiBuilder.Router | HttpRouter.HttpRouter.DefaultServices | HttpApiBuilder.Middleware,
  Cause.UnknownException | PlatformError.PlatformError
>

Added in v1.7.0

make

Makes a lambda handler from the given EffectHandler and optional global layer. The global layer is used to provide a runtime which will gracefully handle lambda termination during down-scaling.

Signature

export declare const make: {
  <T, R, E1, E2, A>(options: EffectHandlerWithLayer<T, R, E1, E2, A>): Handler<T, A>
  <T, E, A>(handler: EffectHandler<T, never, E, A>): Handler<T, A>
  <T, R, E1, E2, A>(handler: EffectHandler<T, R, E1, A>, globalLayer: Layer.Layer<R, E2>): Handler<T, A>
}

Example

import { LambdaHandler, LambdaContext } from "@effect-aws/lambda"
import { Effect } from "effect"

const effectHandler = (event: unknown, context: LambdaContext) => {
  return Effect.logInfo("Hello, world!")
}

export const handler = LambdaHandler.make(effectHandler)

Example

import { LambdaHandler, LambdaContext } from "@effect-aws/lambda"
import { Effect, Logger } from "effect"

const effectHandler = (event: unknown, context: LambdaContext) => {
  return Effect.logInfo("Hello, world!")
}

const LambdaLayer = Logger.replace(Logger.defaultLogger, Logger.logfmtLogger)

export const handler = LambdaHandler.make({
  handler: effectHandler,
  layer: LambdaLayer
})

Added in v1.0.0

makeWebHandler

Construct an WebHandler from an HttpApi instance.

Signature

export declare const makeWebHandler: (
  options?: Pick<HttpApiOptions, "middleware">
) => Effect.Effect<
  WebHandler,
  never,
  | HttpApiBuilder.Router
  | HttpApi.Api
  | HttpRouter.HttpRouter.DefaultServices
  | HttpApiBuilder.Middleware
  | LambdaHandler.Event
  | LambdaContext
>

Added in v1.4.0

stream

Makes a streamify lambda handler from the given StreamHandler and optional global layer. The global layer is used to provide a runtime which will gracefully handle lambda termination during down-scaling.

Signature

export declare const stream: {
  <T, R, E1, E2>(options: StreamHandlerWithLayer<T, R, E1, E2>): Handler<T, void>
  <T, E>(handler: StreamHandler<T, never, E>): Handler<T, void>
}

Example

import { LambdaHandler, LambdaContext } from "@effect-aws/lambda"
import { Stream } from "effect"

const streamHandler = (event: unknown, context: LambdaContext) => {
  return Stream.make("1", "2", "3")
}

export const handler = LambdaHandler.stream(streamHandler)

Example

import { LambdaHandler, LambdaContext } from "@effect-aws/lambda"
import { Stream, Logger } from "effect"

const streamHandler = (event: unknown, context: LambdaContext) => {
  return Stream.make("1", "2", "3")
}

const LambdaLayer = Logger.replace(Logger.defaultLogger, Logger.logfmtLogger)

export const handler = LambdaHandler.stream({
  handler: streamHandler,
  layer: LambdaLayer
})

Added in v1.5.0

streamFromHttpApi

Construct a streaming lambda handler from an HttpApi instance for Lambda Function URLs.

Lambda response streaming is supported by Lambda Function URLs with response streaming enabled, not by API Gateway HTTP API integrations.

Signature

export declare const streamFromHttpApi: <LA, LE>(
  layer: Layer.Layer<LA | HttpApi.Api | HttpRouter.HttpRouter.DefaultServices, LE>,
  options?: HttpApiOptions
) => Handler<LambdaHandler.Event, void>

Example

import { LambdaHandler } from "@effect-aws/lambda"
import { HttpApi, HttpApiBuilder, HttpServer } from "@effect/platform"
import { Layer } from "effect"

class MyApi extends HttpApi.make("api") {}

const MyApiLive = HttpApiBuilder.api(MyApi)

export const handler = LambdaHandler.streamFromHttpApi(Layer.mergeAll(MyApiLive, HttpServer.layerContext))

Added in v1.7.0

context

context

Signature

export declare const context: () => Effect.Effect<LambdaContext>

Added in v1.4.0

event

Signature

export declare const event: <T extends LambdaHandler.Event>() => Effect.Effect<T>

Added in v1.4.0

utils

LambdaHandler (namespace)

Added in v1.4.0

Event (type alias)

Signature

export type Event =
  | ALBEvent
  | APIGatewayProxyEvent
  | APIGatewayProxyEventV2
  | EventBridgeEvent<string, unknown>
  | DynamoDBStreamEvent
  | KinesisStreamEvent
  | S3Event
  | SelfManagedKafkaEvent
  | SNSEvent
  | SQSEvent
  | CloudFrontRequestEvent

Added in v1.4.0

Result (type alias)

Signature

export type Result = ALBResult | APIGatewayProxyResult | APIGatewayProxyResultV2 | void

Added in v1.4.0