Nodejs: Possible to use static class function as lambda handler?

Just for the purposes of organization, I would like to group some code together in a Typescript class. But rather than have a global “export function” declaration outside the class, is it possible to point the serverless handler property at a static function inside the class? Any attempts I’ve made so far have resulted in the “No matching handler found” error.


Can you share some code, that will help.

For example, in src/class.ts:

export class MyClass {
    static async processEvents(event: SNSEvent) {
        some code

Then, in my serverless.yml file, I tried this:

  handler: src/class.MyClass.processEvents

If I run sls package I get the error “No matching handler found for ‘src/class.MyClass’ in ‘<project-dir>’. Check your service definition.”

I do not think its possible but you can export a function and use your class in this function?

Yeah, I already went the route of creating and exporting a stub function but it’s not as pretty. :frowning:

You are right, lets find or create a plugin serverless-class-handler :wink: