def get_cheapest_instance_type(cores, memory):
    """Determine the cheapest instance type given a minimum
    number of cores and minimum amount of RAM (in GB).
    """

    pricelist = get_gcloud_pricelist()

    # Filter out preemptible, shared-CPU, and non-US instance types
    us_instance_types = {k: v for k, v in pricelist.items()
                         if k.startswith('CP-COMPUTEENGINE-VMIMAGE-')
                         and not k.endswith('-PREEMPTIBLE')
                         and 'us' in v and v['cores'] != 'shared'}

    # Convert to array and add keys (instance type names) as type names
    price_array = []
    for key in us_instance_types:
        value = us_instance_types[key]
        value.update({'name': key.replace(
            'CP-COMPUTEENGINE-VMIMAGE-', '').lower()})
        price_array.append(value)

    # Sort by price in US
    price_array.sort(None, lambda x: x['us'])

    # Look for an instance type that satisfies requested
    # cores and memory; first will be cheapest
    for instance_type in price_array:
        if int(instance_type['cores']) >= int(cores) \
           and float(instance_type['memory']) >= float(memory):
            print instance_type['name']
            return instance_type['name']

    # No instance type found that can fulfill requested cores and memory
    raise Exception('No instance type found with at least %d cores '
                    'and %f GB of RAM.' % (cores, memory))