Skip to content

Commit

Permalink
lambda trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek DeJonghe committed Mar 14, 2018
1 parent 6e5d07c commit 10486f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lambda/trigger/lambda_function.py
@@ -0,0 +1,31 @@
#!/usr/bin/env python

import boto3
import os
import random
import string

'''
This lambda handler submits a job to a AWS Batch queue.
JobQueue, and JobDefinition environment variables must be set.
These environment variables are intended to be set to the Name, not the Arn.
'''
def lambda_handler(event,context):
# Grab data from environment
jobqueue = os.environ['JobQueue']
jobdef = os.environ['JobDefinition']

# Create unique name for the job (this does not need to be unique)
job1Name = 'job1' + ''.join(random.choices(string.ascii_uppercase + string.digits, k=4))

# Set up a batch client
session = boto3.session.Session()
client = session.client('batch')

# Submit the job
job1 = client.submit_job(
jobName=job1Name,
jobQueue=jobqueue,
jobDefinition=jobdef
)
print("Started Job: {}".format(job1['jobName']))
1 change: 1 addition & 0 deletions lambda/trigger/requirements.txt
@@ -0,0 +1 @@
boto3>=1.6.0

0 comments on commit 10486f7

Please sign in to comment.