def test_lambda_sns_handler(self, mock_process_payload): lambda_sns_handler(self.get_sns_record()) mock_process_payload.assert_called_with( '{"mess": "age"}', { 'source': 'sns', 'lambda_record': self.get_sns_record() })
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()
def test_lambda_sns_handler_error(self, mock_logging, mock_FSM): mock_FSM.return_value.create_FSM_instance.side_effect = Exception() lambda_sns_handler(self.get_sns_record()) mock_logging.exception.assert_called_with( 'Critical error handling record: %s', {'eventSource': 'aws:sns', 'Sns': {'Message': '{"mess": "age"}'}} )
def test_lambda_sns_handler(self, mock_process_payload): event = { 'Records': [{ 'Sns': { 'Message': json.dumps({"default": json.dumps({"mess": "age"})}) } }] } lambda_sns_handler(event) mock_process_payload.assert_called_with('{"mess": "age"}', {'source': 'sns'})
def test_lambda_sns_handler_error(self, mock_logging, mock_FSM): event = { 'Records': [{ 'Sns': { 'Message': json.dumps({"default": json.dumps({"mess": "age"})}) } }] } mock_FSM.return_value.create_FSM_instance.side_effect = Exception() lambda_sns_handler(event) mock_logging.exception.assert_called_with( 'Critical error handling record: %s', {'Sns': { 'Message': '{"default": "{\\"mess\\": \\"age\\"}"}' }})
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}) } } ] } lambda_sns_handler(lambda_event) if args.run_dynamodb_lambda and dynamodb_conn: # run the dynamodb update handler scanned = dynamodb_conn.scan( TableName=dynamodb_table, ConsistentRead=True, ScanFilter={ STREAM_DATA.TIMESTAMP: { AWS_DYNAMODB.ComparisonOperator: AWS_DYNAMODB.GREATER_THAN, AWS_DYNAMODB.AttributeValueList: [{AWS_DYNAMODB.NUMBER: STARTED_AT}] }, } )