appsync-router
WARNING - Version 4.0.0 is a breaking change from version 3.x.x. Please review the documentation before upgrading
A micro-library that allows for the registration of functions corresponding to AWS AppSync routes. This allows for cleanly creating a single AWS Lambda datasource without large numbers of conditionals to evaluate the called route.
Installation
pip install appsync-router
Basic Usage
from appsync_router import discrete_route, route_event
# Context is a TypedDict that makes access to
# the items passed to your Lambda function simpler
from appsync_router.context import Context
# Here we are telling the router that when the field "getItems"
# is called on the type "Query", call the function "get_items"
@discrete_route("Query", "getItems")
def get_items(context: Context) -> list:
return [1, 2, 3, 4]
def function_handler(event, context):
# simply route the event and return the results
return route_event(event)
NOTE -
appsync-routeris designed to be used as a Direct Invocation AWS AppSync datasource. If you put a request VTL template in front of it, you must pass in the WHOLE $ctx/$context object.
Route Types
Each route type has an overloaded signature allowing for simple declaration.
discrete_route- This discretely routes to a named type and fieldmulti_route- This routes to a set of named type/field combinationspattern_route- This routes to types/fields that match the type and field regex patterns providedglob_route- This routes to the types/fields that match the type and field glob patterns provided
Routing Events
As seen in the example above, the simplest form of event routing is to call route_event with only the event argument. This will do the following:
- Determine the route for the event
- If no route is found, raise
NoRouteFoundException - If more than one route is found, use the first route found
- If no route is found, raise
- Route the event if it is a single context, or map the event to the route if it is multiple contexts
Many times this will be sufficient. However, this behavior can be modified:
- Passing a
default_routeof typeRouteto theroute_eventmethod will call yourdefault_routeif no route is found - Passing
short_circuit=Falseto theroute_eventmethod will cause aMultipleRoutesFoundExceptionto be raised in the case of multiple matched routes. - Passing an
executorof typeconcurrent.futures.Executorto theroute_eventmethod will cause all batch invocations (where theeventhas a list of contexts) to be executed using your executor.
Extensibility
You may extend the appsync_router with your own route types. Any routes that you create must extend from the appsync_router.routes.Route class.
Release files for appsync-router 4.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| appsync-router-4.0.3.tar.gz | 9.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| appsync_router-4.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.3 kB
Release files / appsync-router-4.0.3.tar.gz
| Download URL | appsync-router-4.0.3.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26c4aae28764a503bc59c844acbea6051278a11f74387ca359bbe014d53441cc
|
|
BLAKE2b-256 checksum How to use checksums |
e588ac5ab7bf3dc2444eb6dba71b52ccc0db29e74488a1f9d00750acc8b9b34a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / appsync_router-4.0.3-py3-none-any.whl
| Download URL | appsync_router-4.0.3-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c398afa88bb1a16d273817b469e79cbf0738eaa379a8d2ff746e3d5b1edb111
|
|
BLAKE2b-256 checksum How to use checksums |
b68b98d5a2f76d873acc25f4c8e6ac246752b30f36f49db182294e467cc2f4b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|