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
| Method | Signature | Returns |
|---|---|---|
getHeaders | getHeaders(event: ALBProxyEvent) | Headers |
getPath | getPath(event: ALBProxyEvent) | string |
getMethod | getMethod(event: ALBProxyEvent) | string |
getQueryString | getQueryString(event: ALBProxyEvent) | string |
getCookies | getCookies(event: ALBProxyEvent, headers: Headers) | void |
setCookiesToResult | setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]) | void |
Diagram
mermaidgraph 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
tsimport { 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(), andgetQueryString()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?