def test_lambda_dynamodb_handler(self, mock_process_payload):
     lambda_dynamodb_handler(self.get_dynamodb_record())
     mock_process_payload.assert_called_with(
         '{"pay":"load"}', {
             'source': 'dynamodb_stream',
             'lambda_record': self.get_dynamodb_record()
         })
 def test_lambda_dynamodb_handler_error(self,
                                        mock_logging,
                                        mock_FSM):
     mock_FSM.return_value.create_FSM_instance.side_effect = Exception()
     lambda_dynamodb_handler(self.get_dynamodb_record())
     mock_logging.exception.assert_called_with(
         'Critical error handling record: %s',
         {'eventSource': 'aws:dynamodb', 'dynamodb': {'NewImage': {'payload': {'S': '{"pay":"load"}'}}}}
     )
 def test_lambda_dynamodb_handler(self, mock_process_payload):
     event = {
         'Records': [{
             'dynamodb': {
                 'NewImage': {
                     'payload': {
                         'S': '{"pay":"load"}'
                     }
                 }
             }
         }]
     }
     lambda_dynamodb_handler(event)
     mock_process_payload.assert_called_with('{"pay":"load"}',
                                             {'source': 'dynamodb_stream'})
 def test_lambda_dynamodb_handler_error(self, mock_logging, mock_FSM):
     event = {
         'Records': [{
             'kinesis': {
                 'data':
                 base64.b64encode(
                     json.dumps({'machine_name': 'barfoo'}, sort_keys=True))
             }
         }]
     }
     mock_FSM.return_value.create_FSM_instance.side_effect = Exception()
     lambda_dynamodb_handler(event)
     mock_logging.exception.assert_called_with(
         'Critical error handling record: %s',
         {'kinesis': {
             'data': 'eyJtYWNoaW5lX25hbWUiOiAiYmFyZm9vIn0='
         }})
Esempio n. 5
0
            lambda_event = {
                AWS_LAMBDA.Records: []
            }

            # populate the lambda event
            for record in scanned[AWS_DYNAMODB.Items]:
                correlation_id = record[STREAM_DATA.CORRELATION_ID][AWS_DYNAMODB.STRING]
                payload = record[STREAM_DATA.PAYLOAD][AWS_DYNAMODB.STRING]
                timestamp = record[STREAM_DATA.TIMESTAMP][AWS_DYNAMODB.NUMBER]
                create = correlation_id not in dynamodb_old_images
                update = correlation_id in dynamodb_old_images and payload != dynamodb_old_images[correlation_id]
                if create or update:
                    # this is a CREATE or UPDATE
                    tmp = {
                        AWS_LAMBDA.DYNAMODB_RECORD.DYNAMODB: {
                            AWS_LAMBDA.DYNAMODB_RECORD.NewImage: {
                                STREAM_DATA.PAYLOAD: {
                                    AWS_DYNAMODB.STRING: payload
                                }
                            }
                        }
                    }
                    lambda_event[AWS_LAMBDA.Records].append(tmp)
                    dynamodb_old_images[correlation_id] = payload

            # and call the handler with the records
            if lambda_event[AWS_LAMBDA.Records]:
                lambda_dynamodb_handler(lambda_event)

    time.sleep(args.sleep_time)