import { parser } from '@aws-lambda-powertools/parser/middleware';
import middy from '@middy/core';
import { sqsEnvelope } from '@aws-lambda-powertools/parser/envelopes/sqs;'
const oderSchema = z.object({
id: z.number(),
description: z.string(),
quantity: z.number(),
});
type Order = z.infer<typeof oderSchema>;
export const handler = middy(
async (event: Order, _context: unknown): Promise<void> => {
// event is validated as sqs message envelope
// the body is unwrapped and parsed into object ready to use
// you can now use event as Order in your code
}
).use(parser({ schema: oderSchema, envelope: sqsEnvelope }));
A middiy middleware to parse your event.