As of 16th of march 22, this is finally possible. AWS announced 'shareable test events' that consist of an eventbridge schema, which in turn can be managed with CDK and Terraform.
I found a very useful example for terraform in this Blogpost by tecRacer and used it as guideline for a CDK version. Here a CDK version in Python, using the aws documentation:
def shared_test_event(self, event_id, description, lambda_function_name):
shareable_test = eventschemas.CfnSchema(
self,
event_id,
registry_name="lambda-testevent-schemas",
type="OpenApi3",
# the properties below are optional
description=description,
schema_name=f"_{lambda_function_name}-schema",
tags=[eventschemas.CfnSchema.TagsEntryProperty(
key="Author",
value="Me"
)],
content="""
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Event"
},
"paths": {},
"components": {
"schemas": {
"Event": {
"type": "object",
"required": [
"Parameter1",
"Parameter2"
],
"properties": {
"Parameter1": {
"type": "string"
},
"Parameter2": {
"type": "string"
}
}
}
},
"examples": {
"test with 2 parameters: {
"value": {
"Parameter1": "test",
"Parameter2": "this"
}
},
"Test2": {
"value": {
"Parameter1": "different",
"Parameter2": „values“
}
}
}
}
}
"""
)
Important subtleties:
- The naming of schema_name is important for the association of schema with lambda
- The parameter registry_name defines the type of the event, so it may not be changed, in order to be recognized as shareable lambda test
- The parameter content needs to be provided in json format.