x2faas v0.1.9
X2FaaS lets you outsource parts of a NodeJS app to FaaS (Amazon, Google & IBM)
In addition to existing tools, it supports:
X2FaaS collects anonymous crash analytics with Sentry to help make it better for you.
Install
npm i -g x2faas # install globallyUsage
1. Add annotations in your Monolith code:
// l
var a = 1;
// lend The enclosed code will be packaged into a FaaS function.
2. Run X2FaaS via CLI:
$ x2faas 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 (starts at 0)--outpath PATH: The path where the FaaS function folder should be put`)--provider amazon | google | ibmWhich FaaS provider to outsource to
3. Output
The tool creates an equivalent FaaS function of that section in [--outpath]/['--provider']/[name]:
└── amazon
└── 28723n2398jfs9f87239uhfe9
├── index.js
└── package.json
└── google
└── s940928n38902h2938h293t82
├── index.js
└── package.json You can deploy these folders directly to the respective FaaS platform.
One file can have multiple // l ... // lend sections, that can be converted separately.
Annotation syntax
//l can be followed by any combination of these space-separated directives.
name
You can give your FaaS function a name to better keep track of it:
// l name(myfn)
var a = 1
// lend└── amazon | google | ibm
└── myfn
└── ....
vars
Your code might rely on global variables. You can capture them using vars():
var a = 1
// l vars(a)
a++
// lendThey will be added to the scope inside the FaaS function.
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 FaaS function.
└── amazon | google | ibm
└── 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 as opencv2)
opencv2.detectFaces(...)
// lendreturn
Your monolith code may have no return statement. To receive something back from the FaaS function, 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 install(lodash, rollup, express)
...