DAF lets you outsource parts of a NodeJS app to FaaS
In addition to existing tools, it supports:
npm i -g daf # install globally
// l
var a = 1;
// lend
The enclosed code will be packaged into a FaaS function.
Search for DAF-VSCode on the VSCode Marketplace.
The tool creates an equivalent Lambda function of that section in [--output]/lambdas/[name]
:
└── lambdas
└── 28723n2398jfs9f87239uhfe9
├── index.js
└── package.json
You can zip this folder and upload it directly to Amazon Lambda.
One file can have multiple // l
... // lend
sections, that can be converted separately.
//l
can be followed by any combination of these space-separated directives.
You can give your Lambda a name to better keep track of it:
// l name(mylamb)
var a = 1
// lend
└── lambdas
└── mylamb
└── ....
Your code might rely on functions from other files. You can declare that using require()
:
// l require(./foo.js as foo)
foo()
// lend
A 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.
Your code might depend on NPM packages. You can specify them with install()
. They will be included in your deployment package.
// l install(opencv2)
....
// lend
You probably want to import it as well:
// l install(opencv2) require(opencv2 as opencv2)
opencv2.detectFaces(...)
// lend
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
// lend
With most // l
expressions, you can provide a comma-separated list too:
// l install(lodash, rollup, express)
...