Skip to content

Feature request: implement parser for middy middleware #1792

Closed
@am29d

Description

@am29d

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.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilityparserThis item relates to the Parser Utility

Type

No type

Projects

Status

Shipped

Relationships

None yet

Development

No branches or pull requests

Issue actions