daf v0.0.19
DAF allows you to outsource parts of a NodeJS app to FaaS
In addition to existing tools, it supports:
Install
npm i -g daf # install globallyUsage
Add annotations in your Monolith code:
// l
var a = 1;
// lend Run DAF via Terminal (Not recommended):
$ daf OPTIONS... Options:
--fpath PATH: The path to the.jsfile in which you want to faasify code--linenum NUM: The line number of the// l ...Annotation. Beware, it's 0-indexed.--outpath PATH: The path where the generated FaaS functions will be put (outpath/lambdas/...).--commentout: If specified, the faasified section will be replaced with an Lambda API call. Don't forget to specify//l name(...)!
Run DAF via Editor Extension:
Upcoming: https://github.com/qngapparat/daf-vscode
Output
The tool creates an equivalent Lambda function of that section in [--output]/lambdas/[name]:
└── lambdas
└── 28723n2398jfs9f87239uhfe9
├── index.js
└── package.json You can deploy this function directly to AWS Lambda.
One file can have multiple // l ... // lend sections, that can be converted separately.
Annotations
//l can be followed by any combination of these space-separated directives.
name
You can give your Lambda a name to better keep track of it:
// l name(mylamb)
var a = 1
// lend└── lambdas
└── mylamb
└── ....
vars
Your code might rely on global variables. You can denote them with vars():
var a = 1
// l vars(a)
a++
// lendThey will be added to the scope inside the Lambda.
require
Your code might rely on functions from other files. You can declare that using require():
// l require(./foo.js as foo)
foo()
// lendA portable version of foo.js is then included in the deployment package, and it is added to the scope inside the Lambda.
└── lambdas
└── myfunc
└── foo.js // <---
└── ...If foo in turn depends on other functions or dependencies, they are bundled as well (recursively) using webpack.
install
Your code might depend on NPM packages. You can specify them with install(). They will be included in your deployment package.
// l install(opencv2)
....
// lendYou probably want to import it as well:
// l install(opencv2) require(opencv2)
opencv2.detectFaces(...)
// lendreturn
Your monolith code may have no return statement. To receive something back from the lambda, use return()
// l return(a)
var a = 1
var b = 2
// lendUseful hints
Multiple parameters
With most // l expressions, you can provide a comma-separated list too:
// l vars(a, b, c)
...Aliasing
You can rename functions and packages, when import them:
// l require(opencv2 as cv)
cv.detectFaces(...)
// lendThis is obligatory if you import local functions.
Versioning
You can specify the exact versions of the NPM packages to install:
// l install(pkg1@latest, pkg2^1.0.0, pkg3>=1.2.3)
...
// lendThe syntax follows this official schema: https://docs.npmjs.com/misc/semver