Skip to content

Feature request: pass event, context and request objects into handler #4340

@svozza

Description

@svozza

Use case

When customers create event handlers, they should have access to the raw Lambda event and the Lambda context. We should also expose a fetch Request object for customers who wish to use familiar web standards in their handlers. This is need for both route handlers and error handlers.

Solution/User Experience

Handlers will take an options object with theese objects. The types will look something like this:

type RequestOptions = {
  request: Request;
  event: APIGatewayProxyEvent;
  context: Context;
};

type ErrorResolveOptions = RequestOptions & ResolveOptions;

type ErrorHandler<T extends Error = Error> = (
  error: T,
  options?: RequestOptions
) => Promise<ErrorResponse>;

type RouteHandler<
  TParams = Record<string, unknown>,
  TReturn = Response | JSONObject,
> = (args: TParams, options?: RequestOptions) => Promise<TReturn>;

Alternative solutions

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

event-handlerThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utilitypending-releaseThis item has been merged and will be released soon

Type

Projects

Status

Coming soon

Relationships

None yet

Development

No branches or pull requests

Issue actions