Slambda
Install
npm i --save slambda
Usage
const Slambda = ; // Default valuesconst slambda = autoDeploy: true container: language: 'nodejs4.3' lifecycle: {} {} {} memory: 1024 timeout: 10 storage: execution: ; // Create a containerconst container = slambda; // Create a methodcontainermethod'get:user' { delete userssn; return user;}; // Deploycontainer; // Call methodcontainer ;
Chainable!? The above code can be shortened, as all methods except
.run()
are chainable:
// Create a containerslambda ; method'get:user' { delete userssn; return user; } ;
Adapters
Slambda has two types of adapters, Storage and Execution.
All required adapter methods must return a Bluebird promise.
Storage
Storage adapters tell Slambda how to persist methods and containers. The default is Memory. Storage adapters can take whatever configuration they need.
Required methods:
get(String table, String id)
Returns an entity by ID
findById(String table, String index, String id)
Query table by index. Resolves to an array.
list(String table)
Resolves a list of entities from the specified table
put(String table, Object item)
Upserts an entity
delete(String table, String id)
Deletes specified entity by ID
Note: All storage adapter methods must return a Bluebird promise
Officially supported storage adapters:
- Memory (default)
- DynamoDB
- FileSystem (Coming soon)
- AWS S3 (Coming soon)
- MongoDB (Coming soon)
- Github (Coming soon)
Execution
Execution adapters tell Slambda how to run your code snippets. The default is Memory.
Required methods:
run(String containerId, String methodId, Array methodArguments)
Run a single method with arguments. Returns a promise with the results
deploy(Container container, Array<Method> methods)
Deploy a container and it's functions to the execution layer
execute(String containerId, Array<String id, Array arguments> calls)
Run a batch of method calls. Must return an equal length array as calls
.
Array order must not change.
Note: All storage adapter methods must return a Bluebird promise
Where possible, the .run()
method should try to batch requests.
Officially supported execution adapters:
- Memory (default)
- Local (File system)
- AWS Lambda
- Google Cloud Functions (Coming soon)
- Docker (Coming soon)
- AWS EC2 (Coming soon)
API
Slambda
constructor(Object options)
Parameters
Object options
Defaults
autoDeploy: true container: language: 'nodejs4.3' lifecycle: {} {} {} memory: 1024 timeout: 10 storage: execution:
container(String id, Object options)
Returns
Container
Parameters
String id
Container ID Required
Object options
Defaults to this.options.container
Container
constructor(Object options)
Parameters
Object options
Defaults
language: 'nodejs4.3' lifecycle: {} {} {} memory: 1024 timeout: 10
method(String id, String|Function code)
Returns
Container
Parameters
String id
Container-unique identifier for the method
String|Function code
Method code.
run(String id, Array args)
Returns
Promise
Parameters
String id
Method ID to run
Array args
Arguments passed to method
deploy()
Deploys function to execution layer. Queues .run()
commands
behind deployment
Returns
Container