Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middy handler always requires an async handler #1096

Closed
minjie0501 opened this issue Sep 4, 2023 · 3 comments · Fixed by #1102
Closed

Middy handler always requires an async handler #1096

minjie0501 opened this issue Sep 4, 2023 · 3 comments · Fixed by #1102
Assignees
Milestone

Comments

@minjie0501
Copy link

minjie0501 commented Sep 4, 2023

Describe the bug
The middy handler always expects the lambda handler to return void or Promise<any>. Now i have to make my handlers async even if they don't do any async tasks. I would like to use it with a synchronous handler.

To Reproduce
How to reproduce the behaviour:
Sample code:

import middy from "@middy/core";
import { APIGatewayProxyEvent, Context } from "aws-lambda";

const lambdaHandler = (event: APIGatewayProxyEvent, context: Context) => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: "Hello world!",
      input: event,
    }),
  };
};

export const handler = middy(lambdaHandler);

Thrown error:
Type '{ statusCode: number; body: string; }' is not assignable to type 'void | Promise<any>'.

Expected behaviour
Middy should allow sync handlers

Environment (please complete the following information):

  • Node.js: 18
  • Middy: 4.6.1
@willfarrell
Copy link
Member

Sounds like the types need to be updated. Like to put a PR together?

@cjbt
Copy link
Contributor

cjbt commented Sep 12, 2023

Took a stab at this: #1102. Let me know if I'm missing anything.

@minjie0501
Copy link
Author

Took a stab at this: #1102. Let me know if I'm missing anything.

Haven't really had time to take a look myself, thanks for the PR! 🙌

@willfarrell willfarrell added this to the v5 milestone Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants