Created
June 13, 2016 07:10
-
-
Save meisheep/e3372c63d9152e060070e0e9bdf04bf8 to your computer and use it in GitHub Desktop.
Trigger EMR by Lambda using Boto3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import json | |
import boto3 | |
import os | |
import time | |
client = boto3.client('emr') | |
s3client = boto3.client('s3') | |
job_id = os.urandom(16).encode('hex') | |
city_dict = {'TPE': 'A','NTP': 'F','TY': 'H','HCC': 'J','HC': 'O','ML': 'K','TC': 'B','NT': 'M','CH': 'N','YUL': 'P','CY': 'I','CYC': 'Q','TN': 'D','KH': 'E','PT': 'T','KL': 'C','YIL': 'G','HL': 'U','TT': 'V'} | |
def lambda_handler(event, context): | |
output = {'success': True, 'id': job_id} | |
job_name = 'Job' + job_id | |
try: | |
response = client.add_job_flow_steps( | |
JobFlowId='j-3W014JHSFXXR8', | |
Steps=[ | |
{ | |
'Name': 'Find Factor', | |
'HadoopJarStep': { | |
'Jar': 's3n://cp2016-final-dataset/FindFac.jar', | |
'MainClass': 'FindFac.Main', | |
'Args': [ | |
's3n://cp2016-final-dataset/findFac-input', | |
'cp2016-final-dataset/wip/' + job_id, | |
event['lat'], | |
event['lng'] | |
] | |
} | |
}, | |
{ | |
'Name': 'Calc Score', | |
'HadoopJarStep': { | |
'Jar': 's3n://cp2016-final-dataset/CalScore.jar', | |
'MainClass': 'CalScore.Main', | |
'Args': [ | |
's3n://cp2016-final-dataset/CalScore-input', | |
'cp2016-final-dataset/wip/' + job_id + '/part-r-00000', | |
's3n://cp2016-final-dataset/outputs/' + job_id, | |
city_dict[event['area']], | |
event['price'] | |
] | |
} | |
} | |
] | |
) | |
except: | |
output['success'] = False | |
return output | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment