#NEWLINE# def event_source_mapping_present( name , EventSourceArn , FunctionName , StartingPosition , Enabled = True , BatchSize = 100 , region = None , key = None , keyid = None , profile = None ) : #NEWLINE# #INDENT# '\n    Ensure event source mapping exists.\n\n    name\n        The name of the state definition.\n\n    EventSourceArn\n        The Amazon Resource Name (ARN) of the Amazon Kinesis or the Amazon\n        DynamoDB stream that is the event source.\n\n    FunctionName\n        The Lambda function to invoke when AWS Lambda detects an event on the\n        stream.\n\n        You can specify an unqualified function name (for example, "Thumbnail")\n        or you can specify Amazon Resource Name (ARN) of the function (for\n        example, "arn:aws:lambda:us-west-2:account-id:function:ThumbNail"). AWS\n        Lambda also allows you to specify only the account ID qualifier (for\n        example, "account-id:Thumbnail"). Note that the length constraint\n        applies only to the ARN. If you specify only the function name, it is\n        limited to 64 character in length.\n\n    StartingPosition\n        The position in the stream where AWS Lambda should start reading.\n        (TRIM_HORIZON | LATEST)\n\n    Enabled\n        Indicates whether AWS Lambda should begin polling the event source. By\n        default, Enabled is true.\n\n    BatchSize\n        The largest number of records that AWS Lambda will retrieve from your\n        event source at the time of invoking your function. Your function\n        receives an event with all the retrieved records. The default is 100\n        records.\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' : None , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# r = __salt__ [ 'boto_lambda.event_source_mapping_exists' ] ( EventSourceArn = EventSourceArn , 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 event source mapping: {0}.' . format ( r [ 'error' ] [ 'message' ] ) #NEWLINE# return ret #NEWLINE# #UNINDENT# if ( not r . get ( 'exists' ) ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Event source mapping {0} is set to be created.' . format ( FunctionName ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# r = __salt__ [ 'boto_lambda.create_event_source_mapping' ] ( EventSourceArn = EventSourceArn , FunctionName = FunctionName , StartingPosition = StartingPosition , Enabled = Enabled , BatchSize = BatchSize , 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 event source mapping: {0}.' . format ( r [ 'error' ] [ 'message' ] ) #NEWLINE# return ret #NEWLINE# #UNINDENT# _describe = __salt__ [ 'boto_lambda.describe_event_source_mapping' ] ( EventSourceArn = EventSourceArn , FunctionName = FunctionName , region = region , key = key , keyid = keyid , profile = need_update ) #NEWLINE# ret [ 'name' ] = _describe [ 'event_source_mapping' ] [ 'UUID' ] #NEWLINE# ret [ 'changes' ] [ 'old' ] = { #NEWLINE# #INDENT# 'event_source_mapping' : None , #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'changes' ] [ 'new' ] = _describe #NEWLINE# ret [ 'comment' ] = 'Event source mapping {0} created.' . format ( ret [ 'name' ] ) #NEWLINE# return ret #NEWLINE# #UNINDENT# ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'Event source mapping is present.' ] ) #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# _describe = __salt__ [ 'boto_lambda.describe_event_source_mapping' ] ( EventSourceArn = EventSourceArn , FunctionName = FunctionName , region = region , key = key , keyid = keyid , profile = profile ) [ 'event_source_mapping' ] #NEWLINE# need_update = False #NEWLINE# for ( val , var ) in { #NEWLINE# #INDENT# 'BatchSize' : 'BatchSize' , #NEWLINE# #UNINDENT# } . iteritems ( ) : #NEWLINE# #INDENT# if ( _describe [ val ] != locals ( ) [ var ] ) : #NEWLINE# #INDENT# need_update = True #NEWLINE# ret [ 'changes' ] . setdefault ( 'new' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) [ var ] = locals ( ) [ var ] #NEWLINE# ret [ 'changes' ] . setdefault ( 'old' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) [ var ] = _describe [ val ] #NEWLINE# #UNINDENT# #UNINDENT# function_arn = _get_function_arn ( FunctionName , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# if ( _describe [ 'FunctionArn' ] != function_arn ) : #NEWLINE# #INDENT# need_update = True #NEWLINE# ret [ 'changes' ] . setdefault ( 'new' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) [ 'FunctionArn' ] = function_arn #NEWLINE# ret [ 'changes' ] . setdefault ( 'old' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) [ 'FunctionArn' ] = _describe [ 'FunctionArn' ] #NEWLINE# #UNINDENT# if need_update : #NEWLINE# #INDENT# ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'Event source mapping to be modified' ] ) #NEWLINE# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = 'Event source mapping {0} set to be modified.' . format ( _describe [ 'UUID' ] ) #NEWLINE# ret [ 'comment' ] = msg #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# _r = __salt__ [ 'boto_lambda.update_event_source_mapping' ] ( UUID = _describe [ 'UUID' ] , FunctionName = FunctionName , Enabled = Enabled , BatchSize = BatchSize , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# if ( not _r . get ( 'updated' ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Failed to update mapping: {0}.' . format ( _r [ 'error' ] [ 'message' ] ) #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# return ret