Skip to content

Feature request: implement parser for middy middleware #1792

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

Closed
1 of 2 tasks
am29d opened this issue Nov 14, 2023 · 3 comments · Fixed by #1823
Closed
1 of 2 tasks

Feature request: implement parser for middy middleware #1792

am29d opened this issue Nov 14, 2023 · 3 comments · Fixed by #1823
Assignees
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility parser This item relates to the Parser Utility

Comments

@am29d
Copy link
Contributor

am29d commented Nov 14, 2023

Use case

Using middy middleware we should be able to parse event based on built in schema or provided custom schema with envelopes.

Solution/User Experience

import { parser } from '@aws-lambda-powertools/parser/middleware';
import middy from '@middy/core';
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes';
 
const order = z.object({
    id: z.number(),
    description: z.string(),
    items: z.array(orderItem),
});
 
const lambdaHandler = async (_event: z.infer<typeof order>, _context: any) => {
    logger.info('This is an INFO log with some context');
    logger.info(_event);
    // will output {id: 1, description: 'foo', items: [...]
};

export const handler = middy(lambdaHandler).use(parser(order, envelope));

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

@am29d am29d added triage This item has not been triaged by a maintainer, please wait feature-request This item refers to a feature request for an existing or new utility labels Nov 14, 2023
@am29d am29d added this to the Parser - Beta Release milestone Nov 14, 2023
@am29d am29d added parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Nov 14, 2023
@dreamorosi
Copy link
Contributor

I would make the middleware accept an object rather than positional arguments, i.e.

type ParserOptions = {
  schema: Foo,
  envelope: Bar
};

@am29d am29d self-assigned this Nov 20, 2023
@am29d am29d moved this from Backlog to Working on it in Powertools for AWS Lambda (TypeScript) Dec 7, 2023
@dreamorosi dreamorosi linked a pull request Dec 19, 2023 that will close this issue
9 tasks
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Dec 20, 2023
@dreamorosi dreamorosi added the confirmed The scope is clear, ready for implementation label Dec 20, 2023
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed confirmed The scope is clear, ready for implementation labels Jan 26, 2024
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Jan 26, 2024
@dreamorosi
Copy link
Contributor

This is now released under v2.1.0 version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility parser This item relates to the Parser Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants