def get_step_id_by_name()

in automation/lambda/handlers/index.py [0:0]


def get_step_id_by_name(emr_step_name, cluster_id, emr_client):
    # Default result to null
    step_id = None

    # Query for all running, pending and cancel pending steps
    response = emr_client.list_steps(
        ClusterId=cluster_id,
        StepStates=['RUNNING', 'PENDING', 'CANCEL_PENDING']
    )

    # Loop through result for comparison
    for step in response['Steps']:
        if emr_step_name == step['Name']:
            if step['Status']['State'] in ['PENDING', 'RUNNING']:
                step_id = step['Id']

    return step_id