-
Notifications
You must be signed in to change notification settings - Fork 154
Feature request: sequential async processing #1829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @revmischa thank you for taking the time to open this issue. As we discussed in Discord, I think the request is valid and I remember hearing it from other customers in the past few weeks. I'm adding this to the backlog so that it can be picked up. If anyone is interested in contributing, please leave a comment so we dan discuss an implementation. |
I also have a use case where I have an async handler but need to process FIFO events sequentially. I think it's a safe assumption that most every handler anyone will ever write will be async. How else will do you I/O otherwise? And what is the use of a handler that can't do I/O? |
That's very fair, we are focused on releasing v2 this & next week. After that we'll be able to reprise working on new features for the existing utilities. This is one of the issues I'd like to pick up relatively soon. |
I can work on this next. I can see there is a section in the doc about Async processing,
So, based on the PR description, do we now want to have the option to use |
Also just curious, what is the use case for sync processing? You can't really do I/O without async right? So what use is a SQS processing function that can't do any I/O? |
Hi @arnabrahman - thank you for reviving the conversation on this feature request. When we initially ported the Batch Processing utility from the Python version of Powertools for AWS Lambda, we did so mirroring their preferred patterns: meaning we made the synchronous & sequential processor the default, and the asynchronous & parallel one the alternative one. In hindsight, this was a mistake because - as @revmischa points out - in modern Node.js working with In the next release, and before the utility was considered generally available we corrected this and made the Currently the async processing only supports processing the items in the batch in parallel (implementation is here). For example, today you can do this, which will call the import {
BatchProcessor,
EventType,
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import type { SQSRecord, SQSHandler } from 'aws-lambda';
const processor = new BatchProcessor(EventType.SQS);
const recordHandler = async (record: SQSRecord): Promise<void> => {
// ... do your async processing
};
export const handler: SQSHandler = async (event, context) =>
processPartialResponse(event, recordHandler, processor, {
context,
}); As part of this feature request we should allow customers to also use sequential processing, with a flag similar to this: import {
BatchProcessor,
EventType,
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import type { SQSRecord, SQSHandler } from 'aws-lambda';
const processor = new BatchProcessor(EventType.SQS);
const recordHandler = async (record: SQSRecord): Promise<void> => {
// ... do your async processing
};
export const handler: SQSHandler = async (event, context) =>
processPartialResponse(event, recordHandler, processor, {
context,
processInParallel: false // new flag, name to be confirmed
}); I'm not 100% sold on the name of the option being
Consequentially, regardless of the name we choose for the option, we will have to modify the Regarding the |
I ran in to this same issue and solved it by writing my own implementation that extends the BasePartialBatchProcessor. |
Hey @mpiltz , that's good to hear, glad it worked well for you! Are you interested in contributing the changes in a PR? Happy to collaborate and iterate together. |
I have encountered this issue at work and now understand what's needed. I will take this @dreamorosi |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This is now released under v2.9.0 version! |
Use case
Sometimes I have records that I want processed one at a time, but my processor function happens to be async.
Solution/User Experience
It would be nice to request sequential processing of records with async handlers.
Alternative solutions
No response
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: