spring-media / aws-lambda-router

Improved routing for AWS Lambda like SNS and ApiGateway
Apache License 2.0
98 stars 52 forks source link

Multiple handlers within one event #50

Open evgenykireev opened 4 years ago

evgenykireev commented 4 years ago

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.