/aws-batch-triggering-lambda

AWS Batch Trigger Lambda [ARCHIVED](pre serverless project, unused and likely to be in the future. )

Primary LanguageJavaScript

AWS Batch Triggering Lambda

Build Status codecov

Lambda to trigger AWS Batch Jobs

About

This Node Lambda is to trigger a job on AWS batch from a Lambda.

This lambda can be triggered by a standard event (from a CloudWatch cron for instance, and a lambda call), by a kinesis, a SNS or SQS message.

Usage

The lambda expect the following payload:

{
  "jobDefinition": "the-job-definition",
  "jobQueue": "the-job-queue",
  "jobName": "the-job-name",
  "parameters": {
     "some": "optional parameter"
  },
  "dependsOn": [{"jobId": "other-job-name"}]
}

This can be transmitted through the event, or an Kinesis/Sns/SQS event.

jobDefinition, jobQueue parameters are mandatory. parameters object is optional. dependsOn array is optional too

A jobName would be added based on the following logic :

  • jobName if such key exist
  • jobNamePrefix if defined followed by a date and a random string
  • jobDefinition otherwise followed by a date and a random string

For the two last option name would look like this: test-from-lambda-via-sns--2017-09-21T13-28-55--f6c83928fa175106ea35fd0ff31068e6

The lambda will respond with either an error (and reason why) or a json with the following format:

{
  "jobName": "the-job-name",
  "jobId": "b3e985b1-e02a-41c9-ac8f-4801e04c9a27-whatever"
}

Configuration

You can customize the lambda through environment variable to enable or not the supported event Sources:

  • aws:sns: SNS triggers
  • aws:kinesis: Kinesis triggers
  • aws:sqs: SQS triggers

To do so, use either AWS_BATCH_TRIGGER_ENABLE and AWS_BATCH_TRIGGER_DISABLE that accept a ; separated whitelist/blacklist.

It's also possible to restrict the jobs and/or the queue on which the job can be invocated. To do so, use the AWS_BATCH_JOB_WHITELIST and AWS_BATCH_QUEUE_WHITELIST which accept a ; separated list of pattern (without the ^ and $ at the extremities). (for instance job-queue;staging-.*queue)