falcor-lambda
It creates AWS Lambda handler from Falcor's data source.
You can setup a Falcor endpoint on AWS API Gateway and Lambda using serverless-falcor-starter. This project exposes the Falcor endponit using falcor-lambda.
Usage
You can create a Lambda handler function. For example:
/* handler.js */ ;; moduleexportshandler = ;
API
dataSourceHanlder(sourceCreateFn: SourceCreateFn, option?: Option): LambdaHandlerFunction
function Creates a Lambda handler.
sourceCreateFn
: A function which returns a Falcor DataSource.
SourceCreateFn: (event?: any, context?: any) => DataSource
type event
: An event argument of the AWS Lambda function.context
: A context argument of the AWS Lambda function.
Option: {debug?: boolean, eventToFalcorContext?: (event: any, context: any) => FalcorContext}
type debug
: Allows to output debug log.eventToFalcorContext
: This function creates aFalcorContext
object from the Lambda's event or context value. See also Request and event mapping
FalcorContext: {method: string, jsonGraph?: JSONGraphEnvelope, callPath?: Path, arguments?: any[], pathSuffixes?: Pathset[], paths?: PathSet[]}
type FalcorContext
represents Falcor DataSource's get/set/call
arguments.
Request and event mapping
If you integrate a Lambda handler with AWS API Gateway, you must create a mapping from request to Lambda events with API Request Mapping. falcor-lambda assumes that the request parameter of the GET/POST method will be mapped in the following way:
- GET
"requestTemplates":
- POST
"requestTemplates":
If you want the complete example, please see falcor-lambda-example/falcor/model/s-function.json
By the default, falcor-lambda parses the each value of the event object using JSON.parse
because assumption that they are stringified JSON parameter. If you use other mapping, witch is different from the above sample, you can pass through request values to your DataSource with customizing eventToFalcorContext
.
License
This software is released under the MIT License, see LICENSE.txt.