UNPKG

serverless-aws-lambda

Version:

AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.

129 lines (128 loc) 4.47 kB
import type { PluginBuild, BuildResult } from "esbuild"; import type { Config } from "./config"; import type { ILambdaMock } from "./lib/runtime/rapidApi"; import type { HttpMethod } from "./lib/server/handlers"; import type { IncomingMessage, ServerResponse } from "http"; import type Serverless from "serverless"; import type { SQSClientConfig, SQSClient } from "@aws-sdk/client-sqs"; export type ILambda = { /** * Set environment variable. */ setEnv: (key: string, value: string | null) => void; virtualEnvs?: { [key: string]: any; }; /** * Be notified when this lambda is invoked. * * Can be used to edit (local) input payload before invokation. */ onInvoke: (callback: (event: any, info?: any) => void) => void | { [key: string]: any; }; /** * Called when handler throws an error. */ onInvokeError: (callback: (input: any, error: any, info?: any) => void) => void; /** * Called when handler returns successfully. */ onInvokeSuccess: (callback: (input: any, output: any, info?: any) => void) => void; } & Omit<ILambdaMock, "invokeSub" | "invokeSuccessSub" | "invokeErrorSub" | "runner">; interface IServicesConfig { sqs?: SQSClientConfig; } export interface ClientConfigParams { stop: (err?: any) => Promise<void>; lambdas: ILambda[]; isDeploying: boolean; isPackaging: boolean; /** * @deprecated use `someLambda.setEnv(key, value)` instead. */ setEnv: (lambdaName: string, key: string, value: string) => void; stage: string; region: string; esbuild: PluginBuild["esbuild"]; config: Config; options: Options; serverless: Serverless; resources: { ddb: {}; kinesis: {}; sns: {}; sqs: {}; }; getServices(): { sqs?: SQSClient; }; setServices({ sqs }: IServicesConfig): Promise<void>; } export interface OfflineRequest { /** * @default "ANY" */ method?: HttpMethod | HttpMethod[]; /** * Filter for request path. */ filter: string | RegExp; callback: (this: ClientConfigParams, req: IncomingMessage, res: ServerResponse) => Promise<any | void> | any | void; } export interface SlsAwsLambdaPlugin { name: string; /** * Share any data with other plugins */ pluginData?: any; buildCallback?: (this: ClientConfigParams, result: BuildResult, isRebuild: boolean) => Promise<void> | void; onInit?: (this: ClientConfigParams) => Promise<void> | void; onExit?: (this: ClientConfigParams, code: string | number) => void; afterDeploy?: (this: ClientConfigParams) => Promise<void> | void; afterPackage?: (this: ClientConfigParams) => Promise<void> | void; offline?: { onReady?: (this: ClientConfigParams, port: number, ip: string) => Promise<void> | void; /** * Add new requests to the local server. */ request?: OfflineRequest[]; }; } export interface Options { esbuild?: Config["esbuild"]; /** * shim `require`, `__dirname` and `__filename` when bundeling Lambdas with ESM format * @default true */ shimRequire?: boolean; /** * By default aws sdk packages are excluded from Lambda bundles as AWS Lambda Runtime already includes `aws-sdk` (v2) for Node < 18 and `@aws-sdk/*` for Node >=18 packages. * * Use this option to include aws-sdk if you prefer to control exact package version used by your Lambdas during runtime. * @default false */ includeAwsSdk?: boolean; offline?: { /** * Serve files locally from provided directory */ staticPath?: string; port?: number; }; /** * Only SlsAwsLambdaPlugin type objects are considered as valid plugins. * * Others are ignored. * * This allows conditionnally ( true ?? customPlugin) plugin import. */ plugins?: (SlsAwsLambdaPlugin | null | undefined | boolean)[]; /** * AWS clients configs used by EventSourceMapping, Lambda error/success destination. */ services?: IServicesConfig; } declare function defineConfig(options: Options): (this: ClientConfigParams, { stop, lambdas, isDeploying, isPackaging, setEnv, stage, region, esbuild, serverless, resources, getServices, setServices }: ClientConfigParams) => Promise<Omit<Config, "config" | "options">>; export { defineConfig }; export default defineConfig;