def update_instances(findings):
    """
    For each finding build-up a dict keyed by instance ID with an array value of all applicable
    findings. Then create or update the aws_inspector_findings custom field for each
    corresponding CloudBolt server record.
    :param findings:
    :return:
    """
    instances = {}

    # Group findings by instance
    for finding in findings['findings']:
        instance_id = get_instance_id(finding)
        if instance_id not in instances:
            instances[instance_id] = []
        else:
            instances[instance_id].append(finding)

    # For each istance, find its CloudBolt Server record and update aws_inspector_findings
    for instance in instances.keys():
        try:
            s = Server.objects.get(resource_handler_svr_id=instance)
            cf, _ = CustomField.objects.get_or_create(name='aws_inspector_findings', type='TXT',
                                                      label="AWS Inspector Findings")
            s.set_value_for_custom_field(cf.name, json.dumps(instances[instance], indent=True,
                                                             cls=DjangoJSONEncoder))
        except Server.DoesNotExist as ex:
            # Unable to locate and update the server, carry on
            pass