Skip to content

Types: LambdaEvent type is missing authorizer context for lambda auth #3281

@DaveLo

Description

@DaveLo

What version of Hono are you using?

4.5.3

What runtime/platform is your app running on?

aws lambda

What steps can reproduce the bug?

Create a HTTP Api proxy v2 endpoint in aws-lambda and use a lambda authorizer in front of it, but practically since this is a typings issue you can set up your bindings like:

type Bindings = {
  Bindings: { event: LambdaEvent, lambdaContext:LambdaContext };
  Variables: { userId: string };
};

const app = new Hono<Bindings>();

Then try and set a value from the lambda authorizer context

app.use(async (ctx, next) => {
  ctx.set(
    "userId",
    ctx.env.event.requestConstext.authorizer.lambda.userId
  );
});

This throws up TS warnings because the current setup of LambdaEvent only has a key for iam auth.

What is the expected behavior?

I would expect the types to work correctly.

What do you see instead?

A typescript error.

My current workaround is to do this:

type Event = LambdaEvent & {
  requestContext: {
    authorizer: {
        lambda: { userId: string };
    }
  }
};

type Bindings = {
  Bindings: { event: Event, lambdaContext:LambdaContext };
  Variables: { userId: string };
};

Additional information

I referenced @types/aws-lambda to figure out typings here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions