Handling custom EventBridge events
martoncsikos opened this issue · 4 comments
Hello,
My handler setup:
export const handler = configure({
app,
respondWithErrors: false,
eventSourceRoutes: {
AWS_EVENTBRIDGE: '/eventbridge',
},
});
Event I'm sending via Eventbridge from one of my services:
{
"version": "0",
"id": "46499334-c300-8408-1b83-105d847df24c",
"detail-type": "test",
"source": "mycustomservice",
"account": "12345678910",
"time": "2024-03-11T14:17:01Z",
"region": "eu-central-1",
"resources": [],
"detail": {
"foo": "bar"
}
I'm getting the following error: Error: Unable to determine event source based on event.
I believe the root cause is this:
serverless-express/src/event-sources/utils.js
Line 115 in 1376bd0
The event with source mycustomservice
is not accepted, because the event source does not start with aws.
The aws.
prefix is reserved for events originating from AWS owned services, it's not allowed for custom events.
Per AWS docs the Minimum information needed for a valid custom event is only this much:
{
"detail-type": "event name",
"source": "event source",
"detail": {
}
}
Is it necessary to check the .aws
prefix in the source?
Would it be possible to just check the existence of the minimally required keys in the event and accept them as EventBridge events if they do? That would make it possible to handle customer owned events.
Until then, is it possible to work around this with a custom request mapper?
Awesome library btw, thanks for the great work! Happy to create a PR if needed.
Hey @martoncsikos , if you remove that one line will the rest of the selection criteria work for your event? If so, I'm happy to merge a PR removing that line. If not, we may need to consider a new event like AWS_EVENTBRIDGE_CUSTOM
with less selective criteria. Happy to merge either and can assist where needed (it's not too much; mostly copy-paste-modify)
Hey @brettstack, yes I have tested this in our environment and removing that one line works perfectly fine. I created the PR, just removing the line seems lower impact, so I went with that.
Thanks @martoncsikos ! I appreciate the contribution.
No problem, thanks for the quick resolution!