<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def set_tags(tags,
             name=None,
             group_id=None,
             vpc_name=None,
             vpc_id=None,
             region=None,
             key=None,
             keyid=None,
             profile=None):
    '''
    sets tags on a security group

    .. versionadded:: 2016.3.0

    tags
        a dict of key:value pair of tags to set on the security group

    name
        the name of the security group

    group_id
        the group id of the security group (in lie of a name/vpc combo)

    vpc_name
        the name of the vpc to search the named group for

    vpc_id
        the id of the vpc, in lieu of the vpc_name

    region
        the amazon region

    key
        amazon key

    keyid
        amazon keyid

    profile
        amazon profile

    CLI example:

    .. code-block:: bash

        salt myminion boto_secgroup.set_tags "{'TAG1': 'Value1', 'TAG2': 'Value2'}" security_group_name vpc_id=vpc-13435 profile=my_aws_profile
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    secgrp = _get_group(conn, name=name, vpc_id=vpc_id, vpc_name=vpc_name,
                        group_id=group_id, region=region, key=key, keyid=keyid,
                        profile=profile)

    if secgrp:
        if isinstance(tags, dict):
            secgrp.add_tags(tags)
        else:
            msg = 'Tags must be a dict of tagname:tagvalue'
            raise SaltInvocationError(msg)
    else:
        msg = 'The security group could not be found'
        raise SaltInvocationError(msg)
    return True