aws-lambda-router icon indicating copy to clipboard operation
aws-lambda-router copied to clipboard

Multiple handlers within one event

Open evgenykireev opened this issue 5 years ago • 0 comments

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.

evgenykireev avatar Jul 31 '20 23:07 evgenykireev