@siglo/sqs Adapter Guide
@siglo/sqs provides an AWS SQS batch consumer adapter for executing Siglo workflows. It is optimized for AWS Lambda event source mappings and standalone long-polling worker processes, implementing AWS partial batch failure protocols (ReportBatchItemFailures), message deduplication, and tenant namespace extraction.
1. Overview & Architecture
When AWS Lambda is triggered by an SQS queue, it passes a batch of records (SQSEvent). If one message in the batch fails, returning an uncaught exception causes the entire batch to be retried by AWS, resulting in duplicate processing of previously successful messages.
Furthermore, when concurrent Lambda invocations receive duplicate messages while execution is already underway, @siglo/sqs queries the IdempotencyStore. If an in-progress claim is detected, the adapter marks the message as a batch item failure. This causes SQS to retry the message after the visibility timeout expires rather than executing duplicate concurrent workflows.
@siglo/sqs handles this using AWS SQS Partial Batch Responses:
2. Installation & Requirements
Install@siglo/sqs:
Siglo:*(v1.0.0+)@aws-sdk/client-sqs:^3.0.0(optional if running in AWS Lambda runtime)
3. API Reference
createSqsBatchHandler(workflow, options)
Creates an AWS Lambda-compliant batch processor function:
TypeScript Interfaces
4. Configuration Options (SigloSqsOptions)
5. AWS Lambda Configuration: ReportBatchItemFailures
To enable partial batch responses in AWS Lambda:
- In the AWS Lambda Console, navigate to your SQS Trigger configuration.
- Under Additional settings, check the option: Report batch item failures.
- In AWS SAM / CloudFormation / Serverless Framework / CDK:
{ batchItemFailures: [{ itemIdentifier: 'msg-01' }] } tells AWS SQS to delete all successful messages in the batch from the queue, while leaving only msg-01 in the queue to be retried or routed to the Dead Letter Queue (DLQ).
