-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for DynamoDBTimeWindowEvent and KinesisTimeWindowEvent.
- Loading branch information
1 parent
0e443c1
commit 9a59c02
Showing
18 changed files
with
692 additions
and
5 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
58 changes: 58 additions & 0 deletions
58
Libraries/src/Amazon.Lambda.DynamoDBEvents/DynamoDBTimeWindowEvent.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,58 @@ | ||
namespace Amazon.Lambda.DynamoDBEvents | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Represents an Amazon DynamodDB event when using time windows. | ||
/// https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-windows | ||
/// </summary> | ||
public class DynamoDBTimeWindowEvent : DynamoDBEvent | ||
{ | ||
/// <summary> | ||
/// Time window for the records in the event. | ||
/// </summary> | ||
public TimeWindow Window { get; set; } | ||
|
||
/// <summary> | ||
/// State being built up to this invoke in the time window. | ||
/// </summary> | ||
public Dictionary<string, string> State { get; set; } | ||
|
||
/// <summary> | ||
/// Shard Id of the records. | ||
/// </summary> | ||
public string ShardId { get; set; } | ||
|
||
/// <summary> | ||
/// DynamoDB stream Arn. | ||
/// </summary> | ||
public string EventSourceArn { get; set; } | ||
|
||
/// <summary> | ||
/// Set to true for the last invoke of the time window. Subsequent invoke will start a new time window along with a fresh state. | ||
/// </summary> | ||
public bool? IsFinalInvokeForWindow { get; set; } | ||
|
||
/// <summary> | ||
/// Set to true if window is terminated prematurely. Subsequent invoke will continue the same window with a fresh state. | ||
/// </summary> | ||
public bool? IsWindowTerminatedEarly { get; set; } | ||
|
||
/// <summary> | ||
/// Time window for the records in the event. | ||
/// </summary> | ||
public class TimeWindow | ||
{ | ||
/// <summary> | ||
/// Window start instant. | ||
/// </summary> | ||
public DateTime Start { get; set; } | ||
|
||
/// <summary> | ||
/// Window end instant. | ||
/// </summary> | ||
public DateTime End { get; set; } | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Libraries/src/Amazon.Lambda.DynamoDBEvents/DynamoDBTimeWindowResponse.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,48 @@ | ||
namespace Amazon.Lambda.DynamoDBEvents | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
/// <summary> | ||
/// Response type to return a new state for the time window and to report batch item failures for DynamoDBTimeWindowResponse. | ||
/// </summary> | ||
[DataContract] | ||
public class DynamoDBTimeWindowResponse | ||
{ | ||
/// <summary> | ||
/// New state after processing a batch of records. | ||
/// </summary> | ||
[DataMember(Name = "state")] | ||
#if NETCOREAPP_3_1 | ||
[System.Text.Json.Serialization.JsonPropertyName("state")] | ||
#endif | ||
public Dictionary<String, String> State { get; set; } | ||
|
||
/// <summary> | ||
/// A list of records which failed processing. | ||
/// Returning the first record which failed would retry all remaining records from the batch. | ||
/// </summary> | ||
[DataMember(Name = "batchItemFailures")] | ||
#if NETCOREAPP_3_1 | ||
[System.Text.Json.Serialization.JsonPropertyName("batchItemFailures")] | ||
#endif | ||
public IList<BatchItemFailure> BatchItemFailures { get; set; } | ||
|
||
/// <summary> | ||
/// Class representing the individual record which failed processing. | ||
/// </summary> | ||
[DataContract] | ||
public class BatchItemFailure | ||
{ | ||
/// <summary> | ||
/// Sequence number of the record which failed processing. | ||
/// </summary> | ||
[DataMember(Name = "itemIdentifier")] | ||
#if NETCOREAPP_3_1 | ||
[System.Text.Json.Serialization.JsonPropertyName("itemIdentifier")] | ||
#endif | ||
public string ItemIdentifier { get; set; } | ||
} | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
Libraries/src/Amazon.Lambda.KinesisEvents/KinesisTimeWindowEvent.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,58 @@ | ||
namespace Amazon.Lambda.KinesisEvents | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Represents an Amazon Kinesis event when using time windows. | ||
/// https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html#services-kinesis-windows | ||
/// </summary> | ||
public class KinesisTimeWindowEvent : KinesisEvent | ||
{ | ||
/// <summary> | ||
/// Time window for the records in the event. | ||
/// </summary> | ||
public TimeWindow Window { get; set; } | ||
|
||
/// <summary> | ||
/// State being built up to this invoke in the time window. | ||
/// </summary> | ||
public Dictionary<string, string> State { get; set; } | ||
|
||
/// <summary> | ||
/// Shard Id of the records. | ||
/// </summary> | ||
public string ShardId { get; set; } | ||
|
||
/// <summary> | ||
/// Kinesis stream or consumer ARN. | ||
/// </summary> | ||
public string EventSourceARN { get; set; } | ||
|
||
/// <summary> | ||
/// Set to true for the last invoke of the time window. Subsequent invoke will start a new time window along with a fresh state. | ||
/// </summary> | ||
public bool? IsFinalInvokeForWindow { get; set; } | ||
|
||
/// <summary> | ||
/// Set to true if window is terminated prematurely. Subsequent invoke will continue the same window with a fresh state. | ||
/// </summary> | ||
public bool? IsWindowTerminatedEarly { get; set; } | ||
|
||
/// <summary> | ||
/// Time window for the records in the event. | ||
/// </summary> | ||
public class TimeWindow | ||
{ | ||
/// <summary> | ||
/// Window start instant. | ||
/// </summary> | ||
public DateTime Start { get; set; } | ||
|
||
/// <summary> | ||
/// Window end instant. | ||
/// </summary> | ||
public DateTime End { get; set; } | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Libraries/src/Amazon.Lambda.KinesisEvents/KinesisTimeWindowResponse.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,48 @@ | ||
namespace Amazon.Lambda.KinesisEvents | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
/// <summary> | ||
/// Response type to return a new state for the time window and to report batch item failures for KinesisTimeWindowEvent. | ||
/// </summary> | ||
[DataContract] | ||
public class KinesisTimeWindowResponse | ||
{ | ||
/// <summary> | ||
/// New state after processing a batch of records. | ||
/// </summary> | ||
[DataMember(Name = "state")] | ||
#if NETCOREAPP_3_1 | ||
[System.Text.Json.Serialization.JsonPropertyName("state")] | ||
#endif | ||
public Dictionary<String, String> State { get; set; } | ||
|
||
/// <summary> | ||
/// A list of records which failed processing. | ||
/// Returning the first record which failed would retry all remaining records from the batch. | ||
/// </summary> | ||
[DataMember(Name = "batchItemFailures")] | ||
#if NETCOREAPP_3_1 | ||
[System.Text.Json.Serialization.JsonPropertyName("batchItemFailures")] | ||
#endif | ||
public IList<BatchItemFailure> BatchItemFailures { get; set; } | ||
|
||
/// <summary> | ||
/// Class representing the individual record which failed processing. | ||
/// </summary> | ||
[DataContract] | ||
public class BatchItemFailure | ||
{ | ||
/// <summary> | ||
/// Sequence number of the record which failed processing. | ||
/// </summary> | ||
[DataMember(Name = "itemIdentifier")] | ||
#if NETCOREAPP_3_1 | ||
[System.Text.Json.Serialization.JsonPropertyName("itemIdentifier")] | ||
#endif | ||
public string ItemIdentifier { get; set; } | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...es/src/Amazon.Lambda.Serialization.SystemTextJson/Converters/LongToStringJsonConverter.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,35 @@ | ||
using System; | ||
using System.Buffers; | ||
using System.Buffers.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Amazon.Lambda.Serialization.SystemTextJson.Converters | ||
{ | ||
public class LongToStringJsonConverter : JsonConverter<string> | ||
{ | ||
public override string Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType != JsonTokenType.Number && | ||
type == typeof(String)) | ||
return reader.GetString(); | ||
|
||
var span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan; | ||
|
||
if (Utf8Parser.TryParse(span, out long number, out var bytesConsumed) && span.Length == bytesConsumed) | ||
return number.ToString(); | ||
|
||
var data = reader.GetString(); | ||
|
||
throw new InvalidOperationException($"'{data}' is not a correct expected value!") | ||
{ | ||
Source = "LongToStringJsonConverter" | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.