Created
October 12, 2015 21:35
-
-
Save djamelz/ef743303f1933f66ce2a to your computer and use it in GitHub Desktop.
Sync waiting for the TERMINATED status of an EMR cluster use as : python emr_wait.py us-east-1 j-XXXXXXXXXXXX
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
#!/usr/bin/python | |
import boto.emr | |
import time | |
import sys | |
region = sys.argv[1] | |
clusterId = sys.argv[2] | |
def getStatus(cluster_id): | |
return conn.describe_cluster(cluster_id).status.state | |
#EMR has been started by aws-cli command | |
start_time = time.time() | |
conn = boto.emr.connect_to_region(region) | |
while True: | |
status = getStatus(clusterId) | |
if status=='TERMINATED': | |
print 'Emr Status is finally TERMINATED' | |
break | |
elif status=='TERMINATED_WITH_ERRORS': | |
print 'Errors on the EMR Cluster, please check the log on amazon (console and s3)' | |
sys.exit("EMR_ERROR : TERMINATED_WITH_ERRORS") | |
else: | |
print 'Status is ' + status + ' waiting for 5 more minutes' | |
time.sleep(300) | |
print 'EMR Job finished in ' + str(round((time.time() - start_time)/60, 2)) + ' minutes' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment