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 cloud formation (and also CDK and Terraform).
A solution I found online for cloud formation is this blog post:
Resources:
MyLambdaSampleEventSchema:
Type: AWS::EventSchemas::Schema
Properties:
# do not change. this is where aws stores events created in the Lambda Console
RegistryName: lambda-testevent-schemas
# the name format is key to associate it with the Lambda Function
SchemaName: !Sub
- _${Name}-schema
- Name: !Ref MyLambdaFunction
Type: OpenApi3
# An OpenAPI doc defining all the event schemas
Content: '{}'
for Content, use the following json schema:
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Event"
},
"paths": {},
"components": {
"schemas": {
"Event": {
"type": "object",
"required": [
"foo",
"count"
],
"properties": {
"foo": {
"type": "string"
},
"count": {
"type": "integer"
}
}
},
"examples": {
"my-predefined-event": {
"value": {
"foo": "bar",
"count": 10
}
},
"throws-validation-error": {
"value": {
"foo": "bar"
}
}
}
}
}
I myself used CDK, as described here and a there is also a Terraform example