-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #508 from aws-powertools/develop
chore: Sync main with develop for release 1.8.1
- Loading branch information
Showing
24 changed files
with
527 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 51 additions & 6 deletions
57
libraries/src/AWS.Lambda.Powertools.BatchProcessing/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,59 @@ | ||
# 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](https://docs.powertools.aws.dev/lambda/dotnet/utilities/batch-processing/#sqs-standard). Only messages reported as failure will return to the queue for a retry, while successful ones will be deleted. | ||
* [Kinesis data streams](https://docs.powertools.aws.dev/lambda/dotnet/utilities/batch-processing/#kinesis-and-dynamodb-streams) and [DynamoDB streams](https://docs.powertools.aws.dev/lambda/dotnet/utilities/batch-processing/#kinesis-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/](https://docs.powertools.aws.dev/lambda/dotnet/utilities/batch-processing/) | ||
|
||
GitHub: https://github.com/aws-powertools/powertools-lambda-dotnet/ | ||
|
||
## Sample Function | ||
... | ||
|
||
## Sample output | ||
... | ||
View the full example here: [github.com/aws-powertools/powertools-lambda-dotnet/tree/develop/examples/BatchProcessing](https://github.com/aws-powertools/powertools-lambda-dotnet/tree/develop/examples/BatchProcessing) | ||
|
||
```csharp | ||
[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); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# AWS.Lambda.Powertools.Common | ||
|
||
Powertools for AWS Lambda (.NET) Common library | ||
|
||
### As of release 1.7.0 of Powertools for AWS Lambda (.NET) this package is no longer required. For that reason It’s being deprecated and is no longer maintained. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
libraries/src/AWS.Lambda.Powertools.Logging/Internal/Converters/DateOnlyConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AWS.Lambda.Powertools.Logging.Internal.Converters; | ||
|
||
/// <summary> | ||
/// DateOnly JSON converter | ||
/// </summary> | ||
public class DateOnlyConverter : JsonConverter<DateOnly> | ||
{ | ||
private const string DateFormat = "yyyy-MM-dd"; | ||
|
||
/// <summary> | ||
/// Converts DateOnly from JSON. | ||
/// </summary> | ||
/// <param name="reader"></param> | ||
/// <param name="typeToConvert"></param> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return DateOnly.ParseExact(reader.GetString()!, DateFormat, CultureInfo.InvariantCulture); | ||
} | ||
|
||
/// <summary> | ||
/// Converts DateOnly to JSON. | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
/// <param name="options"></param> | ||
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString(DateFormat, CultureInfo.InvariantCulture)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
libraries/src/AWS.Lambda.Powertools.Logging/Internal/Converters/TimeOnlyConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AWS.Lambda.Powertools.Logging.Internal.Converters; | ||
|
||
/// <summary> | ||
/// TimeOnly JSON converter | ||
/// </summary> | ||
internal class TimeOnlyConverter : JsonConverter<TimeOnly> | ||
{ | ||
private const string TimeFormat = "HH:mm:ss.FFFFFFF"; | ||
|
||
/// <summary> | ||
/// Converts TimeOnly from JSON. | ||
/// </summary> | ||
/// <param name="reader"></param> | ||
/// <param name="typeToConvert"></param> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return TimeOnly.ParseExact(reader.GetString()!, TimeFormat, CultureInfo.InvariantCulture); | ||
} | ||
|
||
/// <summary> | ||
/// Converts TimeOnly to JSON. | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
/// <param name="options"></param> | ||
public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString(TimeFormat, CultureInfo.InvariantCulture)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.