Package: dynamodb-stream-router
dynamodb-stream-routerWARNING - Version 0.0.6 is a breaking change from version 0.0.5. Please review the documentation before upgradingProvies a framework for mapping records in a Dynamodb stream to callables based on the event name (MODIFY, INSERT, DELETE) and content.Installationpipinstalldynamodb-stream-routerRoutingRoutes are determined by examining theeventNamein thedynamodbsection of the DynamoDB streamRecordand through aconditionwhich examines the contents of theRecord.Conditions can either be a callable that takes aRouteRecordand returnsTrueorFalse, or it may be a string expression that will be parsed into a callable. See below for the expression language.Routes have a priority, which is honored in an acending order. If multiple matching routes have the same priority, they will be executed in random order (concurrectly, if anexecutoris provided)Routes are matched based on aRouteRecord, which is a helper class that (lazily) deserializers the DynamoDB item structure (used inKeys,NewImageandOldImage) into Python types, exactly in the same way that the boto3 dynamodb Table resource does.Route handling functions take aRouteRecordand can return anything. The return value is not used by the framework.ExpressionsKeywords and types:TypeDescriptionExampleVALUEA quoted string (single or double quote), integer, or float representing a literal value'foo', 1, 3.8$OLDA reference toRouteRecord.old_image$OLD.foo$NEWA reference toRouteRecord.old_image$NEW.fooPATHA path starting from a root of $OLD or $NEW. Can be specified using dot syntax or python style keys. When using dot reference paths must conform to python's restrictions.$OLD.foo, $NEW.foo.bar, $OLD["foo"]INDEXAn integer used as an index into a list or set$OLD.foo[0]Operators:SymbolAction&Logical AND|Logical OR()Statement grouping==Equality!=Non equality>Greater than>=Greater than or equal to<Less than<=Less than or equal to=~Regex comparisonPATH=~ 'regex' where'regex'is a quotedVALUEComparison operators, except for regex comparison, can comparePATHtoVALUE,PATHtoPATH, or evenVALUEtoVALUE.functionsFunctionArgumentsDescriptionhas_changed(VALUE, VALUE)VALUE - Comma separated list of quoted valuesTests $OLD and $NEW. If value is in one and not the other, or in both and differs, the the function will return True. Returns True if any key meets conditions.is_type(PATH, TYPE)PATH - The path to test in the form of $OLD.foo.bar</liTYPE - A Dynamodb type. Can be one of S, SS, B, BS, N, NS, L, M, or BOOLTests if PATH exists and the VALUE at PATH is of type TYPE.attribute_exists(PATH)PATH - The path to testReturns True if the provided path existsfrom_json(PATH)PATH - The path to decodeReturns object decoded using simplejson.loads()Examplesfromdynamodb_stream_routerimporton_insert,on_modify,on_remove,on_operations,Operation,route_records,RouteRecord@on_insert("$NEW.foo == 'bar'",0)defprint_new_record(record:RouteRecord)->None:print(record.new_image)deftest_old_foo(record:RouteRecord)->bool:returnrecord.old_image["foo"]=="bar2"@on_remove(test_old_foo,0)defprint_old_record(record:RouteRecord)->None:print(record.old_record)@on_modify("has_changed('foo') & attribute_exists($NEW.foo)",1)defprint_changed_foo(record:RouteRecord)->None:print(f'{record.old_image.get("foo")}->{record.new_image.get("foo")}')@on_operations({Operation.INSERT,Operation.MODIFY,Operation.REMOVE},1)defhello_world(record:RouteRecord)->str:return"Hello, DB STREAM"deflambda_handler(event,context):route_records(event["Records"])