#NEWLINE# def create_function( FunctionName , Runtime , Role , Handler , ZipFile = None , S3Bucket = None , S3Key = None , S3ObjectVersion = None , Description = '' , Timeout = 3 , MemorySize = 128 , Publish = False , WaitForRole = False , RoleRetries = 5 , region = None , key = None , keyid = None , profile = None , VpcConfig = None ) : #NEWLINE# #INDENT# '\n    Given a valid config, create a function.\n\n    Returns {created: true} if the function was created and returns\n    {created: False} if the function was not created.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt myminion boto_lamba.create_function my_function python2.7 my_role my_file.my_function my_function.zip\n\n    ' #NEWLINE# role_arn = _get_role_arn ( Role , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# try : #NEWLINE# #INDENT# conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# if ZipFile : #NEWLINE# #INDENT# if ( S3Bucket or S3Key or S3ObjectVersion ) : #NEWLINE# #INDENT# raise SaltInvocationError ( 'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.' ) #NEWLINE# #UNINDENT# code = { #NEWLINE# #INDENT# 'ZipFile' : _filedata ( ZipFile ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not S3Bucket ) or ( not S3Key ) ) : #NEWLINE# #INDENT# raise SaltInvocationError ( 'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.' ) #NEWLINE# #UNINDENT# code = { #NEWLINE# #INDENT# 'S3Bucket' : S3Bucket , #NEWLINE# 'S3Key' : S3Key , #NEWLINE# #UNINDENT# } #NEWLINE# if S3ObjectVersion : #NEWLINE# #INDENT# code [ 'S3ObjectVersion' ] = S3ObjectVersion #NEWLINE# #UNINDENT# #UNINDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( VpcConfig is not None ) : #NEWLINE# #INDENT# kwargs [ 'VpcConfig' ] = VpcConfig #NEWLINE# #UNINDENT# if WaitForRole : #NEWLINE# #INDENT# retrycount = RoleRetries #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# retrycount = 1 #NEWLINE# #UNINDENT# for retry in range ( retrycount , 0 , ( - 1 ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# func = conn . create_function ( FunctionName = FunctionName , Runtime = Runtime , Role = role_arn , Handler = Handler , Code = code , Description = Description , Timeout = Timeout , MemorySize = MemorySize , Publish = key , ** kwargs ) #NEWLINE# #UNINDENT# except ClientError as e : #NEWLINE# #INDENT# if ( ( retry > 1 ) and ( e . response . get ( 'Error' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'Code' ) == 'InvalidParameterValueException' ) ) : #NEWLINE# #INDENT# log . info ( 'Function not created but IAM role may not have propagated, will retry' ) #NEWLINE# time . sleep ( ( ( 2 ** ( RoleRetries - retry ) ) + ( random . randint ( 0 , 1000 ) / 1000 ) ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if func : #NEWLINE# #INDENT# log . info ( 'The newly created function name is {0}' . format ( func [ 'FunctionName' ] ) ) #NEWLINE# return { #NEWLINE# #INDENT# 'created' : True , #NEWLINE# 'name' : func [ 'FunctionName' ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . warning ( 'Function was not created' ) #NEWLINE# return { #NEWLINE# #INDENT# 'created' : False , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# except ClientError as e : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'created' : False , #NEWLINE# 'error' : salt . utils . boto3 . get_error ( e ) , #NEWLINE# #UNINDENT# }