AWS Lambda is a serverless architecture that can run microservices written in haxe and compiled to neko. This project contains the neko runtime as well as an example microservice implementation.
To build the runtime, run the build script included in this project. This will create two zip files in the dist directory.
neko_runtime.zip
is the neko runtimelambda_function.zip
is the example implementation
To install the runtime
- Create a lambda layer
- Create a new version for the new lambda layer
- Upload
neko_runtime.zip
and save - Create lambda function
- Set the Runtime to 'custom'
- Add the new layer you created to the new lambda function
- upload
lambda_function.zip
and save
note: The 'Handler' configuration parameter from the lambda function code configuration panel is not used.
The example lambda function is set up and ready. Here are some test inputs:
- {"a": 1, "b": 2} // returns sum=3
- {"a": 1.1, "b": -2.3} // returns sum=-1.2
- {"a": "car", "b": 2} // returns validation error
- {"one": 1} // returns validation error
To write your own lambda implementation, extend awslambda.base.LambdaFunction
and fill in lambdaHandler(). The request event will be passed in as an anonymous object. lambdaHandler should return an anonymous object with the response, or throw a string containing an error message on failure.
Compile with -lib awslambda-neko
to get the definition of awslambda.base.LambdaFunction
.
The main function that creates your object and calls run()
on the super class is required.
import awslambda.base.LambdaFunction;
class YourLambdaFunction extends LambdaFunction {
public function new() {
super();
}
private override function lambdaHandler( event ){
// validate input
// your implementation here
// return response as an anonymous object
return {};
}
public static function main() {
new YourLambdaFunction().run();
}
}