For creating distributed jobs using AWS Lambda functions.
npm install lambda-hivemind
const Hivemind = require('lambda-hivemind')
const hivemind = new Hivemind({
func: {
name: 'buzzbuzz',
handler: 'buzzbuzz.sting', // '<name of file>.<exported func name>'
role: '<arn of IAM role to run function under>'
},
accessKeyId: '', // AWS credentials. Optional.
secretAccessKey: '' // AWS credentials. Optional.
awsRegion: 'us-east-1',
data: [
'bee 1',
'bee 2',
'bee 3',
...
],
chunkSize: 10 // Size of chunks to split data into
})
// Oh no, we haven't published a function of this name yet!
// List all files you want published as your function
hivemind.publish({
files: [
'buzzbuzz.js'
]
}, {
// Any AWS parameters specified under http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#createFunction-property
})
hivemind.on('create', () => {
// Ok, let's go!
hivemind.run()
})
hivemind.on('finish', (results) => {
// Each job's results will stream to here.
console.log("Woah!")
})
hivemind.on('end', () => {
// All jobs have finished!
process.exit(0)
})
hivemind.on('error', (err) => {
console.log("Aww, man!")
})
func
- Description of functionname
- Name of the functionhandler
(optional) - Handler of function (If your file is named index and your function is named handler, your handler will beindex.handler
) (default: index.handler)role
- ARN of AWS Role to run function underruntime
(optional) - What framework to run function with (default: node6.10)
lambda
(optional) - Overload of AWS Lambda classdata
- Array of data to run onchunkSize
- How many pieces of data to give to each functionaccessKeyId
(optional) - AWS Access keysecretAccessKey
(optional) - AWS Secret keyawsRegion
- AWS region to execute your function in
Publishes or updates specified code as a Lambda function. This method is not required if the function has been previously published and does not need to updated.
zipFile
- Relative path to ZIP file to publish as function. This method is required if your script has dependencies. SeeCode.S3Key
below if your ZIP is over 10MB.files
- Array of relative paths to files to publishlambdaFunc
- JavaScript function to publish as your function. The function must use take 3 parameters (event, context, callback). Data is loaded underevent
,callback
is called when function is done.
Code.S3Key
- Key for file to be used as code (Useful for using ZIP or script stored on S3. Required if your ZIP is over 10MB.)- Any parameter specified here: http://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html
Chunks and runs data given in constructor through the function specified in constructor and published in publish()
AWS credentials in constructor are only optional if you have the AWS CLI configured or have your credentials as environment variables!
Full example can be found under test/
folder.