import click


def validate_tags(value):
    """
    Validate and parse optional EC2 tags.
    """
    err_msg = ("Tags need to be specified as 'Key,Value' pairs "
               "separated by a single comma. Key cannot be empty "
               "or be made up entirely of whitespace.")
    tags = value
    result = []
    for tag in tags:
        if tag.count(',') != 1:
            raise click.BadParameter(err_msg)
        key, value = [word.strip() for word in tag.split(',', maxsplit=1)]
        if not key:
            raise click.BadParameter(err_msg)
        result.append({'Key': key, 'Value': value})

    return result