Add non-standard binaries to serverless compute.
This module reduces the footprint of the run-time only part of the bin-minify module and adds a few AWS Lambda specific functions.
Still, this module's core functionality should work well for other serverless providers as well. Please open an issue if you come across limitations using this module with other serverless providers.
$ npm install --save lambda-bin
const path = require('path');
const LambdaBin = require('lambda-bin');
const MY_LAMBDA_BIN_PATH = path.join('/', 'tmp', 'my_bin');
var myLambdaBin = new LambdaBin({
targetPath: path.resolve(__dirname, path.join('bin', 'my_bin')),
minPack: require('MY_MIN_PACK_FILE'),
});
myLambdaBin.applyMinPack(MY_LAMBDA_BIN_PATH).then((result) => {
if (result.accepted) {
// Setup the PATH environment variable
myLambdaBin.setPath(MY_LAMBDA_BIN_PATH);
// And maybe some other environment variables
myLambdaBin.setEnv({
ENV_VAR1: 'some value',
ENV_VAR2: 'another value',
}, true);
// Or setup the PATH and other environment variables yourself...
}
// Binaries are ready to use
}, error => {
throw new Error(`Binaries could not be correctly setup: ${error}`);
});
Object new LambdaBin( Object )
- Type:
Object
- Optional
The following are supported keys in the options
JSON object. Any other keys are ignored.
- Type:
string
- Default:
./bin/bin-minify
Location of the actual binaries.
Note: Typically the binaries under targetPath
are source controlled (and should be included in the npm module or Lambda package).
- Type:
boolean
Any value passed will be replaced with false
, which is required for bin-minify
to work on AWS Lambda
- Type:
Object
- Default:
{}
Used to load a previously created minPack.
Note: A minPack
is created using bin-minify stagingBin.createMinPack()
and saved to a source controlled file (which should be included in the npm module or Lambda package).
- Type:
string
- Required
Base path where the original file structure of the binaries will be recreated.
Resolved Promise: { loaded: true or false }
. loaded
will be:
true
if the file structure was successfully created.false
if thefromBase
path already existed.
Rejected Promise: { error }
.
Once the original file structure of the binaries is recreated, it is necessary to add them to the PATH
before the binaries can be invoked. setPath()
can be used for this purpose.
- Type:
string
orArray
The path(s) for the binaries. Typically these paths are children of fromBase
and/or fromBase
itself.
Note: These paths will be prepended to the system PATH
.
The resulting PATH
.
Some binaries rely on environment variables to control their behavior (e.g. NODE_PATH
), or require existing environment variables to be updated (e.g. LD_LIBRARY_PATH
). setEnv()
can be used to setup environment variables.
- Type:
Object
Key-values pairs representing the environment variables to add/change, where the key is the environment variable name and the value its associated value.
- Type:
boolean
If true
, any existing value will be replaced. If false
the value provided will be appended to any existing value using ':'.
Tip: If it necessary to overwrite and append values, call setEnv()
twice and change the value of shouldOverwrite
accordingly.
Please keep these AWS lambda limits in mind when deploying lambda functions.
MIT © BotBitsSM