Event Generators¶
An event generator is a simple coroutine used by Smyth to transform a Starlette Request
instance into an event
dictionary that is eventually used when invoking the Lambda handler.
Smyth comes with two built-in event generators: smyth.event.generate_api_gw_v2_event_data
(used by default) and smyth.event.generate_lambda_invocation_event_data
, which is used in the invocation endpoint.
The first one builds a minimal API Gateway Proxy V2 event to simulate a Lambda being triggered by one. The other deserializes the request body (assumes it's proper JSON) and returns just that.
Custom Event Generators¶
Example Generator¶
If you need to work with events not covered by Smyth, you can create and provide your own. Assuming a simplified API Gateway V1 event, you can create a generator like this:
This is example code; a proper API Gateway V1 generator might need to be different.
Configuration¶
Note that smyth_utils
needs to be in your Python path.
From this point on, the order_handler
will receive a different event
than the product_handler
.
Limited Built-in Generators¶
We provided a limited number of generators because there are many possibilities for event simulation. Simulating DynamoDB streams or SQS events locally might be appealing, but we were unsure how these would be used in real-life scenarios. We'd love to hear from the community about this - please don't hesitate to report GitHub issues with proposals on what event generators we should include in Smyth.