def test_get_event_sources_with_paths(self): with self.app.test_request_context(): lambda_api.event_source_mappings.append( { 'UUID': self.TEST_UUID, 'EventSourceArn': 'the_arn/path/subpath' }) # Do partial match on paths result = lambda_api.get_event_sources(source_arn='the_arn') self.assertEqual(len(result), 1) result = lambda_api.get_event_sources(source_arn='the_arn/path') self.assertEqual(len(result), 1)
def test_get_event_sources(self): with self.app.test_request_context(): lambda_api.EVENT_SOURCE_MAPPINGS.append({ 'UUID': self.TEST_UUID, 'EventSourceArn': 'the_arn' }) # Match source ARN result = lambda_api.get_event_sources(source_arn='the_arn') self.assertEqual(len(result), 1) self.assertEqual(result[0].get('UUID'), self.TEST_UUID) # No partial match on source ARN result = lambda_api.get_event_sources(source_arn='the_') self.assertEqual(len(result), 0)
def test_get_event_sources_with_paths(self): region = lambda_api.LambdaRegion.get() with self.app.test_request_context(): region.event_source_mappings.append({ "UUID": self.TEST_UUID, "EventSourceArn": "the_arn/path/subpath" }) # Do partial match on paths result = lambda_api.get_event_sources(source_arn="the_arn") self.assertEqual(1, len(result)) result = lambda_api.get_event_sources(source_arn="the_arn/path") self.assertEqual(1, len(result))
def test_get_event_sources(self): region = lambda_api.LambdaRegion.get() with self.app.test_request_context(): region.event_source_mappings.append({ "UUID": self.TEST_UUID, "EventSourceArn": "the_arn" }) # Match source ARN result = lambda_api.get_event_sources(source_arn="the_arn") self.assertEqual(1, len(result)) self.assertEqual(self.TEST_UUID, result[0].get("UUID")) # No partial match on source ARN result = lambda_api.get_event_sources(source_arn="the_") self.assertEqual(0, len(result))
def test_get_event_sources(self): region = lambda_api.LambdaRegion.get() with self.app.test_request_context(): region.event_source_mappings.append({ 'UUID': self.TEST_UUID, 'EventSourceArn': 'the_arn' }) # Match source ARN result = lambda_api.get_event_sources(source_arn='the_arn') self.assertEqual(len(result), 1) self.assertEqual(result[0].get('UUID'), self.TEST_UUID) # No partial match on source ARN result = lambda_api.get_event_sources(source_arn='the_') self.assertEqual(len(result), 0)
def forward_to_lambda(records): for record in records: sources = lambda_api.get_event_sources(source_arn=record['eventSourceARN']) event = { 'Records': [record] } for src in sources: lambda_api.run_lambda(event=event, context={}, func_arn=src['FunctionArn'])
def forward_to_lambda(records): for record in records: sources = lambda_api.get_event_sources(source_arn=record['eventSourceARN']) event = { 'Records': [record] } for src in sources: lambda_api.run_lambda(event=event, context={}, func_arn=src['FunctionArn'])
def forward_to_lambda(records): for record in records: sources = lambda_api.get_event_sources(source_arn=record['eventSourceARN']) event = { 'Records': [record] } for src in sources: if src.get('State') != 'Enabled': continue lambda_api.run_lambda(func_arn=src['FunctionArn'], event=event, context={}, asynchronous=not config.SYNCHRONOUS_DYNAMODB_EVENTS)
def forward_to_lambda(records): for record in records: sources = lambda_api.get_event_sources( source_arn=record["eventSourceARN"]) event = {"Records": [record]} for src in sources: if src.get("State") != "Enabled": continue lambda_api.run_lambda( func_arn=src["FunctionArn"], event=event, context={}, asynchronous=not config.SYNCHRONOUS_DYNAMODB_EVENTS, )
def has_event_sources_or_streams_enabled(table_name, cache={}): if not table_name: return table_arn = aws_stack.dynamodb_table_arn(table_name) cached = cache.get(table_arn) if isinstance(cached, bool): return cached sources = lambda_api.get_event_sources(source_arn=table_arn) result = False if sources: result = True if not result and dynamodbstreams_api.get_stream_for_table(table_arn): result = True cache[table_arn] = result return result
def has_event_sources_or_streams_enabled(table_name, cache={}): if not table_name: return table_arn = aws_stack.dynamodb_table_arn(table_name) cached = cache.get(table_arn) if isinstance(cached, bool): return cached sources = lambda_api.get_event_sources(source_arn=table_arn) result = False if sources: result = True if not result and dynamodbstreams_api.get_stream_for_table(table_arn): result = True cache[table_arn] = result # if kinesis streaming destination is enabled # get table name from table_arn # since batch_wrtie and transact write operations passing table_arn instead of table_name table_name = table_arn.split('/', 1)[-1] if not result and TABLE_DEFINITIONS.get(table_name): if TABLE_DEFINITIONS[table_name].get( 'KinesisDataStreamDestinationStatus') == 'ACTIVE': result = True return result
def has_event_sources_or_streams_enabled(table_name, cache={}): if not table_name: return table_arn = aws_stack.dynamodb_table_arn(table_name) cached = cache.get(table_arn) if isinstance(cached, bool): return cached sources = lambda_api.get_event_sources(source_arn=table_arn) result = False if sources: result = True if not result and dynamodbstreams_api.get_stream_for_table(table_arn): result = True cache[table_arn] = result # if kinesis streaming destination is enabled # get table name from table_arn # since batch_wrtie and transact write operations passing table_arn instead of table_name table_name = table_arn.split("/", 1)[-1] table_definitions = DynamoDBRegion.get().table_definitions if not result and table_definitions.get(table_name): if table_definitions[table_name].get( "KinesisDataStreamDestinationStatus") == "ACTIVE": result = True return result
def get_matching_event_sources(self) -> List[Dict]: return get_event_sources(source_arn=r".*:sqs:.*")
def _get_matching_event_sources(self) -> List[Dict]: event_sources = get_event_sources(source_arn=r".*:dynamodb:.*") return [source for source in event_sources if source["State"] == "Enabled"]