Namespace: lambda

Interfaces

Type Aliases

ApiGatewayHandlerCallback

Ƭ ApiGatewayHandlerCallback<RequestT>: (request: RequestT, event: APIGatewayProxyEvent, context: Context) => Promise<APIGatewayProxyResult>

Generics type for Lambda callbacks.

Type parameters

Name
RequestT

Type declaration

▸ (request, event, context): Promise<APIGatewayProxyResult>

Parameters
Name Type
request RequestT
event APIGatewayProxyEvent
context Context
Returns

Promise<APIGatewayProxyResult>


AsyncEvent

Ƭ AsyncEvent: Promise<any> | () => Promise<any>


ErrorCallback

Ƭ ErrorCallback<LambdaResponseT>: (error: any) => Promise<LambdaResponseT>

Generics type for Lambda error callbacks.

Type parameters

Name
LambdaResponseT

Type declaration

▸ (error): Promise<LambdaResponseT>

Parameters
Name Type
error any
Returns

Promise<LambdaResponseT>


HandlerCallback

Ƭ HandlerCallback<LambdaEventT, LambdaResponseT>: (event: LambdaEventT, context: Context) => Promise<LambdaResponseT>

Generics type for Lambda callbacks.

Type parameters

Name
LambdaEventT
LambdaResponseT

Type declaration

▸ (event, context): Promise<LambdaResponseT>

Parameters
Name Type
event LambdaEventT
context Context
Returns

Promise<LambdaResponseT>

Functions

apiGatewayErrorHandler

apiGatewayErrorHandler(error): Promise<APIGatewayProxyResult>

Parameters

Name Type
error any

Returns

Promise<APIGatewayProxyResult>


createApiGatewayHandler

createApiGatewayHandler<RequestT>(config): ApiGatewayHandler

Helper for creating API Gateway Lambda handlers.

Type parameters

Name
RequestT

Parameters

Name Type Description
config ApiGatewayHandlerConfig<RequestT> Lambda handler configuration

Returns

ApiGatewayHandler


createHandler

createHandler<LambdaEventT, LambdaResultT>(handler, errorHandler): Handler<LambdaEventT, LambdaResultT>

Helper for creating generic Lambda handlers with unified error handling and logging.

Type parameters

Name
LambdaEventT
LambdaResultT

Parameters

Name Type Description
handler HandlerCallback<LambdaEventT, LambdaResultT> Callback for the actual Lambda logic
errorHandler ErrorCallback<LambdaResultT> Callback for generating an error response

Returns

Handler<LambdaEventT, LambdaResultT>


createScheduledHandler

createScheduledHandler(config): Handler<ScheduledEvent<any>, void>

Helper for creating Scheduled Lambda handlers.

Parameters

Name Type Description
config ScheduledLambdaConfig Lambda handler configuration

Returns

Handler<ScheduledEvent<any>, void>


createWebSocketHandler

createWebSocketHandler<T>(config): ApiGatewayHandler

Helper for creating WebSocket API Gateway Lambda handlers.

Type parameters

Name
T

Parameters

Name Type Description
config WebSocketHandlerConfig<T> Lambda handler configuration

Returns

ApiGatewayHandler


dispatch

dispatch(event): void

Dispatch an async fire-and-forget event. All dispatched events will automatically be awaited before the Lambda exits.

Parameters

Name Type Description
event AsyncEvent Async function to call or Promise to await

Returns

void


invoke

invoke(params): Promise<Lambda.InvocationResponse>

Invokes a specific Lambda function. For an example, see Create the Lambda Function and Test It Manually. If you are using the versioning feature, you can invoke the specific function version by providing function version or alias name that is pointing to the function version using the Qualifier parameter in the request. If you don’t provide the Qualifier parameter, the $LATEST version of the Lambda function is invoked. Invocations occur at least once in response to an event and functions must be idempotent to handle this. For information about the versioning feature, see AWS Lambda Function Versioning and Aliases. This operation requires permission for the lambda:InvokeFunction action. The TooManyRequestsException noted below will return the following: ConcurrentInvocationLimitExceeded will be returned if you have no functions with reserved concurrency and have exceeded your account concurrent limit or if a function without reserved concurrency exceeds the account’s unreserved concurrency limit. ReservedFunctionConcurrentInvocationLimitExceeded will be returned when a function with reserved concurrency exceeds its configured concurrency limit.

Parameters

Name Type
params InvocationRequest

Returns

Promise<Lambda.InvocationResponse>


isAWS

isAWS(): boolean

Check whether the Lambda is running in AWS (as opposed to offline/local execution).

Returns

boolean


setLoggers

setLoggers(logger, errorLogger): void

Set custom logger functions. Defaults to console.log and console.error if null.

Parameters

Name Type Description
logger null | (message?: any, …optionalParams: any[]) => void Logger function for console output
errorLogger null | (message?: any, …optionalParams: any[]) => void Logger function for console errors

Returns

void