Forked from ruanbekker/boto3_emr_create_cluster_with_wordcount_step.py
Created
June 9, 2019 15:41
-
-
Save vaquarkhan/4c2a5ad251d221fdbda184d5eb09f0b4 to your computer and use it in GitHub Desktop.
Create EMR Cluster with a Wordcount Job as a Step in Boto3
This file contains hidden or 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
| import boto3 | |
| client = boto3.client( | |
| 'emr', | |
| region_name='eu-west-1' | |
| ) | |
| cmd = "hadoop jar /usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar wordcount file:///etc/services /output" | |
| emrcluster = client.run_job_flow( | |
| Name='EMR Cluster with Boto', | |
| LogUri='s3://<bucket>/logs/', | |
| ReleaseLabel='emr-5.3.0', | |
| Instances={ | |
| 'InstanceGroups': [ | |
| { | |
| 'Name': "Master nodes", | |
| 'Market': 'ON_DEMAND', | |
| 'InstanceRole': 'MASTER', | |
| 'InstanceType': 'm1.medium', | |
| 'InstanceCount': 1, | |
| }, | |
| { | |
| 'Name': "Slave nodes", | |
| 'Market': 'ON_DEMAND', | |
| 'InstanceRole': 'CORE', | |
| 'InstanceType': 'm1.medium', | |
| 'InstanceCount': 2, | |
| } | |
| ], | |
| 'Ec2KeyName': '<keyname>', | |
| 'KeepJobFlowAliveWhenNoSteps': True, | |
| 'TerminationProtected': False, | |
| 'Ec2SubnetId': 'subnet-<id>', | |
| }, | |
| Steps=[ | |
| { | |
| 'Name': 'Wordcount Job', | |
| 'HadoopJarStep': { | |
| 'Jar': 'command-runner.jar', | |
| 'Args': cmd.split() | |
| } | |
| } | |
| ], | |
| VisibleToAllUsers=True, | |
| JobFlowRole='EMR_EC2_DefaultRole', | |
| ServiceRole='EMR_DefaultRole', | |
| Tags=[ | |
| { | |
| 'Key': 'Name', | |
| 'Value': 'EMR with Boto', | |
| }, | |
| { | |
| 'Key': 'TerminationVal', | |
| 'Value': 'OK', | |
| }, | |
| ], | |
| ) | |
| print( | |
| 'ClusterID: {} , DateCreated: {} , RequestId: {}' | |
| .format( | |
| emrcluster['JobFlowId'], | |
| emrcluster['ResponseMetadata']['HTTPHeaders']['date'], | |
| emrcluster['ResponseMetadata']['RequestId'] | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment