Skip to content

ALBProcessor

reference
1 min readUpdated

Kind: Class

Source: src/adapter/aws-lambda/handler.ts

Part of: Adapter

ALBProcessor adapts an AWS Application Load Balancer request into request values used by the Lambda handler. It reads headers, path, method, query string, and cookies, then writes response cookies back to the ALB result.

Extends: EventProcessor

Methods

MethodSignatureReturns
getHeadersgetHeaders(event: ALBProxyEvent)Headers
getPathgetPath(event: ALBProxyEvent)string
getMethodgetMethod(event: ALBProxyEvent)string
getQueryStringgetQueryString(event: ALBProxyEvent)string
getCookiesgetCookies(event: ALBProxyEvent, headers: Headers)void
setCookiesToResultsetCookiesToResult(result: APIGatewayProxyResult, cookies: string[])void

Diagram

mermaid
graph LR
  ALB[ALB request event] --> Processor[ALBProcessor]
  Processor --> Headers[getHeaders()]
  Processor --> Path[getPath()]
  Processor --> Method[getMethod()]
  Processor --> Query[getQueryString()]
  Processor --> Cookies[getCookies()]
  Handler[Application handler] --> ResponseCookies[Response cookies]
  ResponseCookies --> Processor
  Processor --> Result[ALB response result]
  Processor --> SetCookies[setCookiesToResult()]

Usage

ts
import { ALBProcessor } from './adapter/aws-lambda/handler';

export async function handler(event: unknown) {
  const result = {
    statusCode: 200,
    headers: {},
    body: '',
  };

  const processor = new ALBProcessor(event, result);

  const request = {
    method: processor.getMethod(),
    path: processor.getPath(),
    headers: processor.getHeaders(),
    queryString: processor.getQueryString(),
  };

  processor.getCookies();

  result.body = JSON.stringify({
    method: request.method,
    path: request.path,
    queryString: request.queryString,
  });

  processor.setCookiesToResult();

  return result;
}

AI Coding Instructions

  • Read request metadata through getHeaders(), getPath(), getMethod(), and getQueryString() instead of accessing ALB event fields in application code.
  • Call getCookies() before code that depends on request cookies.
  • Call setCookiesToResult() after response cookies have been added and before returning the ALB result.
  • Keep ALB-specific request and response handling inside this adapter so application handlers remain transport-independent.

Was this page helpful?

Download as PDF
ALBProcessor — Hono (narrator proof)