Ensure alias exists.

    name
        The name of the state definition.

    FunctionName
        Name of the function for which you want to create an alias.

    Name
        The name of the alias to be created.

    FunctionVersion
        Function version for which you are creating the alias.

    Description
        A short, user-defined function description. Lambda does not use this value. Assign a meaningful
        description as you see fit.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.

def alias_present(name, FunctionName, Name, FunctionVersion, Description='',
                  region=None, key=None, keyid=None, profile=None):
    '''
    Ensure alias exists.

    name
        The name of the state definition.

    FunctionName
        Name of the function for which you want to create an alias.

    Name
        The name of the alias to be created.

    FunctionVersion
        Function version for which you are creating the alias.

    Description
        A short, user-defined function description. Lambda does not use this value. Assign a meaningful
        description as you see fit.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    '''
    ret = {'name': Name,
           'result': True,
           'comment': '',
           'changes': {}
           }

    r = __salt__['boto_lambda.alias_exists'](
        FunctionName=FunctionName, Name=Name, region=region,
        key=key, keyid=keyid, profile=profile)

    if 'error' in r:
        ret['result'] = False
        ret['comment'] = ('Failed to create alias: '
                          '{0}.'.format(r['error']['message']))
        return ret

    if not r.get('exists'):
        if __opts__['test']:
            ret['comment'] = 'Alias {0} is set to be created.'.format(Name)
            ret['result'] = None
            return ret
        r = __salt__['boto_lambda.create_alias'](FunctionName, Name,
                                                 FunctionVersion, Description,
                                                 region, key, keyid, profile)
        if not r.get('created'):
            ret['result'] = False
            ret['comment'] = ('Failed to create alias: '
                              '{0}.'.format(r['error']['message']))
            return ret
        _describe = __salt__['boto_lambda.describe_alias'](
            FunctionName, Name, region=region, key=key,
            keyid=keyid, profile=profile)
        ret['changes']['old'] = {'alias': None}
        ret['changes']['new'] = _describe
        ret['comment'] = 'Alias {0} created.'.format(Name)
        return ret

    ret['comment'] = os.linesep.join(
        [ret['comment'], 'Alias {0} is present.'.format(Name)])
    ret['changes'] = {}
    _describe = __salt__['boto_lambda.describe_alias'](
        FunctionName, Name, region=region, key=key, keyid=keyid,
        profile=profile)['alias']

    need_update = False
    options = {'FunctionVersion': FunctionVersion,
               'Description': Description}

    for key, val in six.iteritems(options):
        if _describe[key] != val:
            need_update = True
            ret['changes'].setdefault('old', {})[key] = _describe[key]
            ret['changes'].setdefault('new', {})[key] = val
    if need_update:
        ret['comment'] = os.linesep.join(
            [ret['comment'], 'Alias config to be modified'])
        if __opts__['test']:
            ret['comment'] = 'Alias {0} set to be modified.'.format(Name)
            ret['result'] = None
            return ret
        _r = __salt__['boto_lambda.update_alias'](
            FunctionName=FunctionName, Name=Name,
            FunctionVersion=FunctionVersion, Description=Description,
            region=region, key=key, keyid=keyid, profile=profile)
        if not _r.get('updated'):
            ret['result'] = False
            ret['comment'] = ('Failed to update alias: '
                              '{0}.'.format(_r['error']['message']))
            ret['changes'] = {}
    return ret