generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Labels
area/batchBatch utilityBatch utilityfeature-requestNew or enhancements to existing featuresNew or enhancements to existing features
Description
Use case
Full support for TypedRecordHandler
and TypedRecordHandlerWithContext
[BatchProcessor(TypedRecordHandler = typeof(TypedSqsRecordHandler))]
public BatchItemFailuresResponse HandlerUsingTypedAttribute(SQSEvent _)
{
return TypedSqsBatchProcessor.Result.BatchItemFailuresResponse; // (4)!
}
[BatchProcessor(TypedRecordHandlerWithContext = typeof(ProductHandlerWithContext))]
public BatchItemFailuresResponse ProcessWithContext(SQSEvent sqsEvent, ILambdaContext context)
{
return TypedSqsBatchProcessor.Result.BatchItemFailuresResponse;
}
Solution/User Experience
public class Product
{
public int Id { get; set; }
public string? Name { get; set; }
public decimal Price { get; set; }
}
public class TypedSqsRecordHandler : ITypedRecordHandler<Product> // (1)!
{
public async Task<RecordHandlerResult> HandleAsync(Product product, CancellationToken cancellationToken)
{
/*
* Your business logic with automatic deserialization.
* If an exception is thrown, the item will be marked as a partial batch item failure.
*/
Logger.LogInformation($"Processing product {product.Id} - {product.Name} (${product.Price})");
if (product.Id == 4) // (2)!
{
throw new ArgumentException("Error on id 4");
}
return await Task.FromResult(RecordHandlerResult.None); // (3)!
}
}
[BatchProcessor(TypedRecordHandler = typeof(TypedSqsRecordHandler))]
public BatchItemFailuresResponse HandlerUsingTypedAttribute(SQSEvent _)
{
return TypedSqsBatchProcessor.Result.BatchItemFailuresResponse; // (4)!
}
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (.NET) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and TypeScript
Metadata
Metadata
Assignees
Labels
area/batchBatch utilityBatch utilityfeature-requestNew or enhancements to existing featuresNew or enhancements to existing features
Type
Projects
Status
👀 In review