@lamware/sqs-json-parser
v2.0.1
Published
Lamware Middleware for parsing and providing types for SQS
Downloads
32
Readme
This Lamware Middleware allows you to automatically parse an SQS Queue payload and optionally provide TypeScript typings for the records.
Installation
This package is available via NPM:
yarn add @lamware/sqs-json-parser
# or
npm install @lamware/sqs-json-parser
Usage
import { sqsJsonParser } from '@lamware/sqs-json-parser';
import type { SQSHandler } from 'aws-lambda';
import { lamware } from '@lamware/core';
interface MyRecord {
title: string;
content: string;
}
const { handler } = lamware<SQSHandler>()
.use(sqsJsonParser<MyRecord>({
// [optional] Whether to throw an error if the JSON fails to parse (default: true)
throwOnError: false,
}))
.execute(async ({ state }) => {
console.log(state.items); // MyRecord[]
});
export { handler };