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

def apply_security_groups(name, security_groups, region=None, key=None,
                          keyid=None, profile=None):
    '''
    Apply security groups to ELB.

    CLI example:

    .. code-block:: bash

        salt myminion boto_elb.apply_security_groups myelb '["mysecgroup1"]'
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    if isinstance(security_groups, six.string_types):
        security_groups = salt.utils.json.loads(security_groups)
    try:
        conn.apply_security_groups_to_lb(name, security_groups)
        log.info('Applied security_groups on ELB %s', name)
        return True
    except boto.exception.BotoServerError as e:
        log.debug(e)
        log.error('Failed to appply security_groups on ELB %s: %s',
                  name, e.message)
        return False