-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsertjoblowsteps_to_emr_for_lambda_trigger.py
44 lines (36 loc) · 1.45 KB
/
insertjoblowsteps_to_emr_for_lambda_trigger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import json
import boto3
import logging
from botocore.exceptions import ClientError
import os
def lambda_handler(event, context):
#these cluster id and sparks steps can alo be loaded into a config file or json file and then loaded using agparser
# or can be taken as arguments of python script while submitting the job into cluster using command-runner.jar in EMR clsuter
jobflowid = cluster_id = "j-2xxCUxxxxNXxX"
steps = SPARK_STEPS = [
{
"Name": "incremental-load-lambda-project",
"ActionOnFailure": "CANCEL_AND_WAIT",
"HadoopJarStep": {
"Jar": "command-runner.jar",
"Args": [
"spark-submit",
"--master", "yarn",
"--executor-memory", "2g",
"--executor-cores", "3",
"--deploy-mode",
"cluster",
"s3://s3-lambda-to-s3-project/emr_script/EMR-script-for-lambda-project.py",
],
},
}
]
# Upload the file
emr_client = boto3.client('emr', region_name='ap-south-1', aws_access_key_id='xxxxxxxxxxxx',
aws_secret_access_key='xxxxxxxxxxxxxxxxxxxxxxxx')
try:
response = emr_client.add_job_flow_steps(JobFlowId=jobflowid, Steps=steps)
except ClientError as e:
logging.error(e)
return False
return True