AWS.Lambda.Powertools.BatchProcessing 1.1.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package AWS.Lambda.Powertools.BatchProcessing --version 1.1.1                
NuGet\Install-Package AWS.Lambda.Powertools.BatchProcessing -Version 1.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AWS.Lambda.Powertools.BatchProcessing" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AWS.Lambda.Powertools.BatchProcessing --version 1.1.1                
#r "nuget: AWS.Lambda.Powertools.BatchProcessing, 1.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AWS.Lambda.Powertools.BatchProcessing as a Cake Addin
#addin nuget:?package=AWS.Lambda.Powertools.BatchProcessing&version=1.1.1

// Install AWS.Lambda.Powertools.BatchProcessing as a Cake Tool
#tool nuget:?package=AWS.Lambda.Powertools.BatchProcessing&version=1.1.1                

AWS.Lambda.Powertools.BatchProcessing

The batch processing utility handles partial failures when processing batches from Amazon SQS, Amazon Kinesis Data Streams, and Amazon DynamoDB Streams.

Key features

  • Reports batch item failures to reduce number of retries for a record upon errors
  • Simple interface to process each batch record
  • Bring your own batch processor
  • Parallel processing

Background

When using SQS, Kinesis Data Streams, or DynamoDB Streams as a Lambda event source, your Lambda functions are triggered with a batch of messages.

If your function fails to process any message from the batch, the entire batch returns to your queue or stream. This same batch is then retried until either condition happens first: a) your Lambda function returns a successful response, b) record reaches maximum retry attempts, or c) when records expire.

This behavior changes when you enable Report Batch Item Failures feature in your Lambda function event source configuration:

  • SQS queues. Only messages reported as failure will return to the queue for a retry, while successful ones will be deleted.
  • Kinesis data streams and DynamoDB streams. Single reported failure will use its sequence number as the stream checkpoint. Multiple reported failures will use the lowest sequence number as checkpoint.

Read the docs

For a full list of features go to docs.powertools.aws.dev/lambda/dotnet/utilities/batch-processing/

GitHub: https://github.com/aws-powertools/powertools-lambda-dotnet/

Sample Function

View the full example here: github.com/aws-powertools/powertools-lambda-dotnet/tree/develop/examples/BatchProcessing

[BatchProcessor(RecordHandler = typeof(CustomSqsRecordHandler))]
public BatchItemFailuresResponse HandlerUsingAttribute(SQSEvent _)
{
    return SqsBatchProcessor.Result.BatchItemFailuresResponse;
}

public class CustomSqsRecordHandler : ISqsRecordHandler
{
    public async Task<RecordHandlerResult> HandleAsync(SQSEvent.SQSMessage record, CancellationToken cancellationToken)
    {
        /*
            Your business logic. 
            If an exception is thrown, the item will be marked as a partial batch item failure.
        */
        
        var product = JsonSerializer.Deserialize<JsonElement>(record.Body);

        if (product.GetProperty("Id").GetInt16() == 4)
        {
            throw new ArgumentException("Error on 4");
        }

        return await Task.FromResult(RecordHandlerResult.None);
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on AWS.Lambda.Powertools.BatchProcessing:

Repository Stars
aws-powertools/powertools-lambda-dotnet
Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
Version Downloads Last updated
1.2.0 7,573 10/2/2024
1.1.2 1,895 8/29/2024
1.1.1 8,460 3/10/2024
1.1.0 2,983 2/16/2024
1.0.0 1,555 12/12/2023
0.0.1-preview 728 9/20/2023