Optional type of the deserialized key - defaults to unknown
.
Optional type of the deserialized value - defaults to unknown
.
The original handler function to wrap. It should accept the deserialized event as its first argument.
Optional
config: SchemaConfigThe schema configuration for deserializing and validating record keys and values.
import { kafkaConsumer } from '@aws-lambda-powertools/kafka';
import { z } from 'zod';
const keySchema = z.string();
const valueSchema = z.object({
id: z.number(),
});
export const handler = kafkaConsumer<z.infer<keySchema>, z.infer<valueSchema>>(async (event, context) => {
// event.records is now an array of deserialized and validated records
for (const record of event.records) {
console.log(record.key, record.value);
}
}, {
key: { type: 'json', parserSchema: keySchema },
value: { type: 'json', parserSchema: valueSchema },
});
Wrap a handler function to automatically deserialize and validate Kafka records from an MSK event.
The returned function will:
records
property in the event with an array of deserialized and validated records.