Using Parser With Batch Processor #3309
-
I've been using the parser from the package and its working great. I would like to use the parser in conjunction with batch processing for SQS. When using the parser it overwrites the event in the lambda handler with what you set in the schema but you loose the message id and attributes for the record which are needed. Is there a way to both use the parser but also keep the message id's and attributes in the handler? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @root0x, apologies for the late reply - we missed the notification. You can use both utilities together, however there are some caveats. From your question it seems that you're alluding to the fact that you're using one of the built-in envelopes from Parser rather than one of the schemas. Envelopes extract the payload from an event, in this case the If you want to keep the entire payload, you should instead be using the built-in import { Logger } from '@aws-lambda-powertools/logger';
import { parser } from '@aws-lambda-powertools/parser/middleware';
import { SqsSchema } from '@aws-lambda-powertools/parser/schemas/sqs';
import type { SqsEvent } from '@aws-lambda-powertools/parser/types';
import {
BatchProcessor,
EventType,
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import middy from '@middy/core';
const logger = new Logger({ logLevel: 'debug' });
const batchProcessor = new BatchProcessor(EventType.SQS);
const recordHandler = async (record: SqsEvent['Records'][]) => {
logger.debug('recordHandler', { record });
};
export const handler = middy()
.use(
parser({
schema: SqsSchema,
})
)
.handler(async (event, context) => {
return processPartialResponse(event, recordHandler, batchProcessor, {
context,
});
}); |
Beta Was this translation helpful? Give feedback.
Hi @root0x, apologies for the late reply - we missed the notification.
You can use both utilities together, however there are some caveats.
From your question it seems that you're alluding to the fact that you're using one of the built-in envelopes from Parser rather than one of the schemas. Envelopes extract the payload from an event, in this case the
body
, transform it, and parse it - this means all other fields are dropped.If you want to keep the entire payload, you should instead be using the built-in
SqsSchema
like this: