def test_lambda_kinesis_handler(self, mock_process_payload):
     lambda_kinesis_handler(self.get_kinesis_record())
     mock_process_payload.assert_called_with(
         '{"machine_name": "barfoo"}', {
             'source': 'kinesis',
             'lambda_record': self.get_kinesis_record()
         })
Ejemplo n.º 2
0
 def _execute(self, aws, machine_name, context,
              primary_stream_chaos=0.0,
              secondary_stream_chaos=0.0,
              primary_retry_chaos=0.0,
              secondary_retry_chaos=0.0,
              primary_cache_chaos=0.0,
              secondary_cache_chaos=0.0,
              empty_primary_cache=False,
              empty_secondary_cache=False):
     start_state_machine(machine_name, context, correlation_id='correlation_id')
     if primary_stream_chaos:
         aws.primary_stream_chaos = primary_stream_chaos
     if secondary_stream_chaos:
         aws.secondary_stream_chaos = secondary_stream_chaos
     if primary_retry_chaos:
         aws.primary_retry_chaos = primary_retry_chaos
     if secondary_retry_chaos:
         aws.secondary_retry_chaos = secondary_retry_chaos
     if primary_cache_chaos:
         aws.primary_cache_chaos = primary_cache_chaos
     if secondary_cache_chaos:
         aws.secondary_cache_chaos = secondary_cache_chaos
     if empty_primary_cache:
         aws.empty_primary_cache = empty_primary_cache
     if empty_secondary_cache:
         aws.empty_secondary_cache = empty_secondary_cache
     message = aws.get_message()
     while message:
         if AWS_CONSTANTS.KINESIS == self.MESSAGE_TYPE:
             handler.lambda_kinesis_handler(to_kinesis_message(message))
         elif AWS_CONSTANTS.SQS == self.MESSAGE_TYPE:
             handler.lambda_sqs_handler(to_sqs_message(message))
         elif AWS_CONSTANTS.SNS == self.MESSAGE_TYPE:
             handler.lambda_sns_handler(to_sns_message(message))
         message = aws.get_message()
Ejemplo n.º 3
0
 def _execute(self, aws, machine_name, context,
              primary_stream_chaos=0.0,
              secondary_stream_chaos=0.0,
              primary_retry_chaos=0.0,
              secondary_retry_chaos=0.0,
              primary_cache_chaos=0.0,
              secondary_cache_chaos=0.0,
              empty_primary_cache=False,
              empty_secondary_cache=False):
     start_state_machine(machine_name, context, correlation_id='correlation_id')
     if primary_stream_chaos:
         aws.primary_stream_chaos = primary_stream_chaos
     if secondary_stream_chaos:
         aws.secondary_stream_chaos = secondary_stream_chaos
     if primary_retry_chaos:
         aws.primary_retry_chaos = primary_retry_chaos
     if secondary_retry_chaos:
         aws.secondary_retry_chaos = secondary_retry_chaos
     if primary_cache_chaos:
         aws.primary_cache_chaos = primary_cache_chaos
     if secondary_cache_chaos:
         aws.secondary_cache_chaos = secondary_cache_chaos
     if empty_primary_cache:
         aws.empty_primary_cache = empty_primary_cache
     if empty_secondary_cache:
         aws.empty_secondary_cache = empty_secondary_cache
     message = aws.get_message()
     while message:
         handler.lambda_kinesis_handler(to_kinesis_message(message))
         message = aws.get_message()
 def test_lambda_kinesis_handler_error(self,
                                       mock_logging,
                                       mock_FSM):
     mock_FSM.return_value.create_FSM_instance.side_effect = Exception()
     lambda_kinesis_handler(self.get_kinesis_record())
     mock_logging.exception.assert_called_with(
         'Critical error handling record: %s',
         {'eventSource': 'aws:kinesis', 'kinesis': {'data': 'eyJtYWNoaW5lX25hbWUiOiAiYmFyZm9vIn0='}}
     )
Ejemplo n.º 5
0
 def test_lambda_kinesis_handler_error(self, mock_logging, mock_FSM):
     mock_FSM.return_value.create_FSM_instance.side_effect = Exception()
     lambda_kinesis_handler(self.get_kinesis_record(),
                            self.get_kinesis_context())
     mock_logging.exception.assert_called_with(
         'Critical error handling record: %s', {
             'eventSource': 'aws:kinesis',
             'kinesis': {
                 'data': '[REDACTED]'
             }
         })
 def test_lambda_kinesis_handler(self, mock_process_payload):
     event = {
         'Records': [{
             'kinesis': {
                 'data':
                 base64.b64encode(
                     json.dumps({'machine_name': 'barfoo'}, sort_keys=True))
             }
         }]
     }
     lambda_kinesis_handler(event)
     mock_process_payload.assert_called_with('{"machine_name": "barfoo"}',
                                             {'source': 'kinesis'})
 def test_lambda_kinesis_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_kinesis_handler(event)
     mock_logging.exception.assert_called_with(
         'Critical error handling record: %s',
         {'kinesis': {
             'data': 'eyJtYWNoaW5lX25hbWUiOiAiYmFyZm9vIn0='
         }})
Ejemplo n.º 8
0
            # process any results that are available
            if out[AWS_KINESIS.Records]:

                # create the lambda event
                lambda_event = {
                    AWS_LAMBDA.Records: []
                }

                # populate the lambda event
                for record in out[AWS_KINESIS.Records]:
                    data = record[AWS_KINESIS.RECORD.Data]
                    tmp = {AWS_LAMBDA.KINESIS_RECORD.KINESIS: {AWS_LAMBDA.KINESIS_RECORD.DATA: base64.b64encode(data)}}
                    lambda_event[AWS_LAMBDA.Records].append(tmp)

                # and call the handler with the records
                lambda_kinesis_handler(lambda_event)

    if args.run_sns_lambda and sns_server:

        sns_server.handle_request()
        message = sns_server.message
        if message:
            lambda_event = {
                AWS_LAMBDA.Records: [
                    {
                        AWS_LAMBDA.SNS_RECORD.SNS: {
                            AWS_LAMBDA.SNS_RECORD.Message: json.dumps({AWS_LAMBDA.SNS_RECORD.DEFAULT: message})
                        }
                    }
                ]
            }