aws-lambda-router
aws-lambda-router copied to clipboard
Multiple handlers within one event
We often need to do routing to an appropriate handler based on an attribute of a particular record within an event. For example, we have a generic SQS topic with a number of handlers based on an attribute of SQL message. You have a similar concept for HTTP Proxy integration when you match a request based on the path.
Are there any plans to support this in this library?
The way I'd imagine it could work is to add records attribute to multi-record event like sqs. This attribute defines a match and handler functions. For example,
export const handler = router.handler({
sqs: {
routes: [
{
source: /.*notification/,
records: {
match(record) => record.type === 'user',
handler(record) => service.doNotify(record)
}
}
]
}
})
Happy to collaborate on this.