Skip to content

Passing a JS/TS lambda handler by reference instead of src path #1068

@maciejgoscinski

Description

@maciejgoscinski

Hello!

At the moment, the only way to connect a lambda handler function to an APIGw route (or Function construct) is to pass it as a string path:
src/blabla/certainLambdasFile.handlerFunction. This is consistent with how CloudFormation refers to the handler method, but otherwise pretty gimmicky as something to be written "by hand".

When working in an all-typescript project, possibly a monorepo, it would be super handy to pass the handler by reference:

import { handlerFunction} from 'src/blabla/certainLambdasFile';

// ...
'GET /myLambda' : handlerFunction
// ..

There's been a discussion on Slack explaining it's rather difficult from the architecture standpoint.

Perhaps it would be possible to bypass the architectural problems, by "cheating" at build-time, swapping the references with their paths?

Also, is a "freely dangling" exported function the only way to export a handler? Would a class method, or the following syntax be possible anyhow?

export function MyLambdas() {
   function handler() { }

   return { handler }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions