def _get_cluster_name(instance: 'boto3.resources.factory.ec2.Instance') ->str:
    """
    Given an EC2 instance, get the name of the Flintrock cluster it belongs to.
    """
    for group in instance.security_groups:
        if group['GroupName'].startswith('flintrock-'):
            return group['GroupName'].replace('flintrock-', '', 1)
    else:
        raise Exception('Could not extract cluster name from instance: {i}'
            .format(i=instance.id))
