#NEWLINE# 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 ) : #NEWLINE# #INDENT# "\n    Ensure function exists.\n\n    name\n        The name of the state definition\n\n    FunctionName\n        Name of the Function.\n\n    Runtime\n        The Runtime environment for the function. One of\n        'nodejs', 'java8', or 'python2.7'\n\n    Role\n        The name or ARN of the IAM role that the function assumes when it executes your\n        function to access any other AWS resources.\n\n    Handler\n        The function within your code that Lambda calls to begin execution. For Node.js it is the\n        module-name.*export* value in your function. For Java, it can be package.classname::handler or\n        package.class-name.\n\n    ZipFile\n        A path to a .zip file containing your deployment package. If this is\n        specified, S3Bucket and S3Key must not be specified.\n\n    S3Bucket\n        Amazon S3 bucket name where the .zip file containing your package is\n        stored. If this is specified, S3Key must be specified and ZipFile must\n        NOT be specified.\n\n    S3Key\n        The Amazon S3 object (the deployment package) key name you want to\n        upload. If this is specified, S3Key must be specified and ZipFile must\n        NOT be specified.\n\n    S3ObjectVersion\n        The version of S3 object to use. Optional, should only be specified if\n        S3Bucket and S3Key are specified.\n\n    Description\n        A short, user-defined function description. Lambda does not use this value. Assign a meaningful\n        description as you see fit.\n\n    Timeout\n        The function execution time at which Lambda should terminate this function. Because the execution\n        time has cost implications, we recommend you set this value based on your expected execution time.\n        The default is 3 seconds.\n\n    MemorySize\n        The amount of memory, in MB, your function is given. Lambda uses this memory size to infer\n        the amount of CPU and memory allocated to your function. Your function use-case determines your\n        CPU and memory requirements. For example, a database operation might need less memory compared\n        to an image processing function. The default value is 128 MB. The value must be a multiple of\n        64 MB.\n\n    VpcConfig\n        If your Lambda function accesses resources in a VPC, you provide this\n        parameter identifying the list of security group IDs and subnet IDs.\n        These must belong to the same VPC. You must provide at least one\n        security group and one subnet ID.\n\n        .. versionadded:: Carbon\n\n    Permissions\n        A list of permission definitions to be added to the function's policy\n\n    RoleRetries\n        IAM Roles may take some time to propagate to all regions once created.\n        During that time function creation may fail; this state will\n        atuomatically retry this number of times. The default is 5.\n\n    region\n        Region to connect to.\n\n    key\n        Secret key to be used.\n\n    keyid\n        Access key to be used.\n\n    profile\n        A dict with region, key and keyid, or a pillar key (string) that\n        contains a dict with region, key and keyid.\n    " #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : FunctionName , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# if ( Permissions is not None ) : #NEWLINE# #INDENT# if isinstance ( Permissions , string_types ) : #NEWLINE# #INDENT# Permissions = json . loads ( Permissions ) #NEWLINE# #UNINDENT# required_keys = set ( ( 'Action' , 'Principal' ) ) #NEWLINE# optional_keys = set ( ( 'SourceArn' , 'SourceAccount' ) ) #NEWLINE# for ( sid , permission ) in Permissions . iteritems ( ) : #NEWLINE# #INDENT# keyset = set ( permission . keys ( ) ) #NEWLINE# if ( not keyset . issuperset ( required_keys ) ) : #NEWLINE# #INDENT# raise SaltInvocationError ( '{0} are required for each permission specification' . format ( ', ' . join ( required_keys ) ) ) #NEWLINE# #UNINDENT# keyset = ( keyset - required_keys ) #NEWLINE# keyset = ( keyset - optional_keys ) #NEWLINE# if bool ( keyset ) : #NEWLINE# #INDENT# raise SaltInvocationError ( 'Invalid permission value {0}' . format ( ', ' . join ( keyset ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# r = __salt__ [ 'boto_lambda.function_exists' ] ( FunctionName = FunctionName , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# if ( 'error' in r ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Failed to create function: {0}.' . format ( r [ 'error' ] [ 'message' ] ) #NEWLINE# return ret #NEWLINE# #UNINDENT# if ( not r . get ( 'exists' ) ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Function {0} is set to be created.' . format ( FunctionName ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# r = __salt__ [ 'boto_lambda.create_function' ] ( FunctionName = FunctionName , Runtime = Runtime , Role = Role , Handler = Handler , ZipFile = ZipFile , S3Bucket = S3Bucket , S3Key = S3Key , S3ObjectVersion = S3ObjectVersion , Description = Description , Timeout = Timeout , MemorySize = MemorySize , VpcConfig = VpcConfig , WaitForRole = True , RoleRetries = RoleRetries , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# if ( not r . get ( 'created' ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Failed to create function: {0}.' . format ( r [ 'error' ] [ 'message' ] ) #NEWLINE# return ret #NEWLINE# #UNINDENT# if Permissions : #NEWLINE# #INDENT# for ( sid , permission ) in Permissions . iteritems ( ) : #NEWLINE# #INDENT# r = __salt__ [ 'boto_lambda.add_permission' ] ( FunctionName = FunctionName , StatementId = sid , region = region , key = key , keyid = keyid , profile = profile , ** permission ) #NEWLINE# if ( not r . get ( 'updated' ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Failed to create function: {0}.' . format ( r [ 'error' ] [ 'message' ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# _describe = __salt__ [ 'boto_lambda.describe_function' ] ( FunctionName , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# _describe [ 'function' ] [ 'Permissions' ] = __salt__ [ 'boto_lambda.get_permissions' ] ( FunctionName , region = region , key = key , keyid = keyid , profile = profile ) [ 'permissions' ] #NEWLINE# ret [ 'changes' ] [ 'old' ] = { #NEWLINE# #INDENT# 'function' : None , #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'changes' ] [ 'new' ] = _describe #NEWLINE# ret [ 'comment' ] = 'Function {0} created.' . format ( FunctionName ) #NEWLINE# return ret #NEWLINE# #UNINDENT# ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'Function {0} is present.' . format ( FunctionName ) ] ) #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# _ret = _function_config_present ( FunctionName , Role , Handler , Description , Timeout , MemorySize , VpcConfig , region , key , keyid , profile , RoleRetries ) #NEWLINE# if ( not _ret . get ( 'result' ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = _ret [ 'comment' ] #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# return ret #NEWLINE# #UNINDENT# ret [ 'changes' ] = dictupdate . update ( ret [ 'changes' ] , _ret [ 'changes' ] ) #NEWLINE# ret [ 'comment' ] = ' ' . join ( [ ret [ 'comment' ] , _ret [ 'comment' ] ] ) #NEWLINE# _ret = _function_code_present ( FunctionName , ZipFile , S3Bucket , S3Key , S3ObjectVersion , region , key , keyid , profile ) #NEWLINE# if ( not _ret . get ( 'result' ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = _ret [ 'comment' ] #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# return ret #NEWLINE# #UNINDENT# ret [ 'changes' ] = dictupdate . update ( ret [ 'changes' ] , _ret [ 'changes' ] ) #NEWLINE# ret [ 'comment' ] = ' ' . join ( [ ret [ 'comment' ] , _ret [ 'comment' ] ] ) #NEWLINE# _ret = _function_permissions_present ( FunctionName , Permissions , region , key , keyid , profile ) #NEWLINE# if ( not _ret . get ( 'result' ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = _ret [ 'comment' ] #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# return ret #NEWLINE# #UNINDENT# ret [ 'changes' ] = dictupdate . update ( ret [ 'changes' ] , _ret [ 'changes' ] ) #NEWLINE# ret [ 'comment' ] = ' ' . join ( [ ret [ 'comment' ] , _ret [ 'comment' ] ] ) #NEWLINE# return ret