@webda/aws
Version:
Webda AWS Services implementation
87 lines (86 loc) • 2.34 kB
TypeScript
import { Core as Webda, HttpContext, WebContext } from "@webda/core";
import { Context as LambdaContext } from "aws-lambda";
/**
* Handler for AWS Events definition
*/
export interface AWSEventsHandler {
/**
* Return true if event is handled
* @param source
* @param event
*/
isAWSEventHandled(source: string, events: any): boolean;
/**
*
* @param source
* @param event
*/
handleAWSEvent(source: string, events: any): Promise<void>;
}
/**
* The Lambda entrypoint for Webda
*
* This take the input coming from the API Gateway to transform it and analyse it with Webda
* Once execution is done, it will format the result in a way that the API Gateway will output the result
* You need to use the Webda deployment so the API Gateway has all the right templates in place
*
* @class
*/
export default class LambdaServer extends Webda {
_result: {
headers?: any;
statusCode?: number;
multiValueHeaders?: any;
body?: any;
};
_awsEventsHandlers: AWSEventsHandler[];
/**
* @ignore
*/
flushHeaders(ctx: WebContext): void;
/**
* @inheritdoc
*/
flush(ctx: WebContext): void;
/**
* Register a service to handle AWS Events
* @param service
*/
registerAWSEventsHandler(service: AWSEventsHandler): void;
private handleAWSEvent;
/**
* Analyse events to try to find its type
* @param events
* @returns
*/
handleAWSEvents(events: any): Promise<boolean>;
/**
* Need to unit test this part, with sample of data coming from the API Gateway
*
* @ignore
*/
handleRequest(sourceEvent: any, context: LambdaContext): Promise<{
headers?: any;
statusCode?: number;
multiValueHeaders?: any;
body?: any;
}>;
/**
* Based on API Gateway event compute the prefix if any
* @param event
* @param httpContext
*/
computePrefix(event: any, httpContext: HttpContext): void;
/**
* Collect result from Context to this._result and return it
* @param context
* @returns
*/
handleLambdaReturn(context: WebContext): Promise<{
headers?: any;
statusCode?: number;
multiValueHeaders?: any;
body?: any;
}>;
}
export { LambdaServer };