<commit_before># -*- coding: utf-8 -*-
'''
Manage Lambda Functions
=======================

.. versionadded:: 2016.3.0

Create and destroy Lambda Functions. Be aware that this interacts with Amazon's services,
and so may incur charges.

:depends:
    - boto
    - boto3

The dependencies listed above can be installed via package or pip.

This module accepts explicit vpc credentials but can also utilize
IAM roles assigned to the instance through Instance Profiles. Dynamic
credentials are then automatically obtained from AWS API and no further
configuration is necessary. More information available `here
<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.

If IAM roles are not used you need to specify them either in a pillar file or
in the minion's config file:

.. code-block:: yaml

    vpc.keyid: <KEY>
    vpc.key: <KEY>

It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile,
either passed in as a dict, or as a string to pull from pillars or minion
config:

.. code-block:: yaml

    myprofile:
        keyid: <KEY>
        key: <KEY>
            region: us-east-1

.. code-block:: yaml

    Ensure function exists:
        boto_lambda.function_present:
            - FunctionName: myfunction
            - Runtime: python2.7
            - Role: iam_role_name
            - Handler: entry_function
            - ZipFile: code.zip
            - S3Bucket: bucketname
            - S3Key: keyname
            - S3ObjectVersion: version
            - Description: "My Lambda Function"
            - Timeout: 3
            - MemorySize: 128
            - region: us-east-1
            - keyid: <KEY>
            - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

'''

# Import Python Libs
from __future__ import absolute_import
import logging
import os
import os.path
import hashlib
import json

# Import Salt Libs
import salt.ext.six as six
import salt.utils.dictupdate as dictupdate
import salt.utils
from salt.exceptions import SaltInvocationError
from salt.utils.odict import OrderedDict

log = logging.getLogger(__name__)


def __virtual__():
    '''
    Only load if boto is available.
    '''
    return 'boto_lambda' if 'boto_lambda.function_exists' in __salt__ else False


def function_present(name, FunctionName, Runtime, Role, Handler, ZipFile=None,
                     S3Bucket=None, S3Key=None, S3ObjectVersion=None,
                     Description='', Timeout=3, MemorySize=128,
                     Permissions=None, RoleRetries=5, region=None, key=None,
                     keyid=None, profile=None, VpcConfig=None,
                     Environment=None):
    '''
    Ensure function exists.

    name
        The name of the state definition

    FunctionName
        Name of the Function.<commit_msg>INFRA-4506 - remove unused import to quiet pylint<commit_after># -*- coding: utf-8 -*-
'''
Manage Lambda Functions
=======================

.. versionadded:: 2016.3.0

Create and destroy Lambda Functions. Be aware that this interacts with Amazon's services,
and so may incur charges.

:depends:
    - boto
    - boto3

The dependencies listed above can be installed via package or pip.

This module accepts explicit vpc credentials but can also utilize
IAM roles assigned to the instance through Instance Profiles. Dynamic
credentials are then automatically obtained from AWS API and no further
configuration is necessary. More information available `here
<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.

If IAM roles are not used you need to specify them either in a pillar file or
in the minion's config file:

.. code-block:: yaml

    vpc.keyid: <KEY>
    vpc.key: <KEY>

It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile,
either passed in as a dict, or as a string to pull from pillars or minion
config:

.. code-block:: yaml

    myprofile:
        keyid: <KEY>
        key: <KEY>
            region: us-east-1

.. code-block:: yaml

    Ensure function exists:
        boto_lambda.function_present:
            - FunctionName: myfunction
            - Runtime: python2.7
            - Role: iam_role_name
            - Handler: entry_function
            - ZipFile: code.zip
            - S3Bucket: bucketname
            - S3Key: keyname
            - S3ObjectVersion: version
            - Description: "My Lambda Function"
            - Timeout: 3
            - MemorySize: 128
            - region: us-east-1
            - keyid: <KEY>
            - key: <KEY>

'''

# Import Python Libs
from __future__ import absolute_import
import logging
import os
import os.path
import hashlib
import json

# Import Salt Libs
import salt.ext.six as six
import salt.utils.dictupdate as dictupdate
import salt.utils
from salt.exceptions import SaltInvocationError

log = logging.getLogger(__name__)


def __virtual__():
    '''
    Only load if boto is available.
    '''
    return 'boto_lambda' if 'boto_lambda.function_exists' in __salt__ else False


def function_present(name, FunctionName, Runtime, Role, Handler, ZipFile=None,
                     S3Bucket=None, S3Key=None, S3ObjectVersion=None,
                     Description='', Timeout=3, MemorySize=128,
                     Permissions=None, RoleRetries=5, region=None, key=None,
                     keyid=None, profile=None, VpcConfig=None,
                     Environment=None):
    '''
    Ensure function exists.

    name
        The name of the state definition

    FunctionName
        Name of the Function.
{'fraction_non_alphanumeric': 0.08822997649611282, 'fraction_numerical': 0.011209546194178268, 'mean_word_length': 2.519083969465649, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256034', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1542, 'n_words': 547}