lambda-phi
Typescript framework for AWS API Gateway and Lambda
Features
- Supports HTTP verbs method mapping. See Sample Convention
- Supports event inject fallback. See Sample
- Supports body mapping variable alias.
- Supports multiple HTTP verbs to a method. See sample.
- Supports catch all http verbs. See sample.
- Supports method call before lambda function timeout. See sample
- Supports method call before running lambda callback(). See sample
- Supports route mapping and path parameter parsing. See sample
Sample Convention
;; @ @ context; @ callback; @Event event; @ headers; // Content-Type, Authorization, etc.. @ pathParams; // /users/{id} --> this.pathParams.id @ queryParams; // ?param1=value1 --> this.queryParams.param1 @ method; // GET, POST, ... @ body; // HTTP request body content @ public { console; } @ public { this; } @ public { this; } @ public { this; } @ public { this; } exportshandler = LambdaHandler;
Event inject fallback
This framework adds fallback to common event
mapping fields, specially if you're using default passthrough or proxy template
@Body()
- event.body
- event['body-json']
@Header()
- event.headers
- event.params.header
@Method()
- event.method
- event.httpMethod
- event.context['http-method']
@PathParams()
- event.pathParams
- event.pathParameters
- event.params.path
@QueryParams()
- event.queryParams
- event.queryStringParameters
- event.params.querystring
@StageVariables()
- event.stageVariables
- event['stage-variables]
@EventContext()
- event.context
- event.requestContext
Body mapping variable alias
If you're using different Body Mapping variables, you can use the alias feature.
//... //... @ qParams; //...//...
If you want to map it to multiple aliases
//... //... @ pathParams; //...//...
If you want to map it to a deeper variable, like event.context['http-method'].
//... //... @ method; //...//...
Multiple methods in a function.
//... //... @ @ public { this; } //...//...
Forward all method types to a function.
//... // This method will be called if the method type is PUT,POST,GET, etc.. @ public { this; } //...//...
PreLambdaTimeout
If you want to call a method 2 seconds before your lambda function reach its timeout limit
@ public { console; }
PreLambdaCallback
If you want to call a method before running lambda callback() function
tasks:string = ; @ public { thistasks; } @ public { thistasks; this; }
Output: ["Do this task","Do this pre callback task"]
Path Examples
path-to-regexp package for pattern matching. The default resource path is parse from event.context['resource-path']
Path usesmyPath()
will be triggered if the request path is /my/path
In this example, @ public { this; }
Setting default base path
@@ @ public { this; } @ public { this; }
Configure a different resource path variable. This will target event.context['resource-path']
@@ @ public { this; }
Defining route with path parameter support
@ public this; @ public this;
Defining route with HTTP filter
@ @ @ public { this }