def extract_attr_for_match(items, **kwargs):
    """Helper method to get attribute value for an item matching some criterion.
  Specify target criteria value as dict, with target attribute having value -1

  Example:
    to extract state of vpc matching given vpc id

  response = [{'State': 'available', 'VpcId': 'vpc-2bb1584c'}]
  extract_attr_for_match(response, State=-1, VpcId='vpc-2bb1584c') #=> 'available'"""
    query_arg = None
    for arg, value in kwargs.items():
        if value == -1:
            assert query_arg is None, 'Only single query arg (-1 valued) is allowed'
            query_arg = arg
    result = []
    filterset = set(kwargs.keys())
    for item in items:
        match = True
        assert filterset.issubset(item.keys()
            ), 'Filter set contained %s which was not in record %s' % (
            filterset.difference(item.keys()), item)
        for arg in item:
            if arg == query_arg:
                continue
            if arg in kwargs:
                if item[arg] != kwargs[arg]:
                    match = False
                    break
        if match:
            result.append(item[query_arg])
    assert len(result) <= 1, '%d values matched %s, only allow 1' % (len(
        result), kwargs)
    if result:
        return result[0]
    return None
