Repository navigation
Closed
Labels
bugThis issue is a bug.This issue is a bug.module/lambda-client-libp2This is a standard priority issueThis is a standard priority issuequeuedresponse-requestedWaiting on additional info and feedback. Will move to close soon in 7 days.Waiting on additional info and feedback. Will move to close soon in 7 days.
Description
Description
I'm creating a lambda to process DynamoDB events streamed through Kinesis, which means they're wrapped in base64, etcetera. During processing I pull them out and then deserialize them to DynamoDBv2 records:
var serializer = new Amazon.Lambda.Serialization.Json.JsonSerializer();
var dynamoEvent = serializer.Deserialize<Amazon.DynamoDBv2.Model.Record>(BaseObserver.GenerateStreamFromString(dynamoData));
Reproduction Steps
This gist: https://gist.github.com/cdegroot/6e8e1957d9d08a595b3918dce3e16d84. Note that all I did was to add a couple of zeros to the test event.
Logs
Stacktrace:
X TestDynamoParsing [8ms]
Error Message:
Test method Canary.EventStore.Tests.BaseObserverTests.TestDynamoParsing threw exception:
Amazon.Lambda.Serialization.Json.JsonSerializerException: Error converting the Lambda event JSON payload to type Amazon.DynamoDBv2.Model.Record: Value to add was out of range. (Parameter 'value') ---> System.ArgumentOutOfRangeException: Value to add was out of range. (Parameter 'value')
Stack Trace:
at System.DateTime.Add(Double value, Int32 scale)
at System.DateTime.AddSeconds(Double value)
at Amazon.Lambda.Serialization.Json.JsonNumberToDateTimeDataConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
at Amazon.Lambda.Serialization.Json.JsonSerializer.Deserialize[T](Stream requestStream)
--- End of inner exception stack trace ---
at Amazon.Lambda.Serialization.Json.JsonSerializer.Deserialize[T](Stream requestStream
Environment
- Build Version: 1.2.0
- OS Info: Ubuntu 20.10
- Build Environment: Terminal
dotnet testetc. - Targeted .NET Platform: 3.1
Resolution
- 👋 I can/would-like-to implement a fix for this problem myself
I can look later, will just kill the last three digits with a regex for now, but the usual fix is to take a cut-off value (100000000000 - somewhere in the 6th millenium) and if it's above, interpret as millisecs, if not, as secs.
Of course, the proper fix is to make DynamoDB emit always one or the other :)
This is a 🐛 bug-report
Reacted by shooresh-golzari-cko, Adam Birch and JM89
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.module/lambda-client-libp2This is a standard priority issueThis is a standard priority issuequeuedresponse-requestedWaiting on additional info and feedback. Will move to close soon in 7 days.Waiting on additional info and feedback. Will move to close soon in 7 days.
Activity
ashishdhingra commentedon Mar 23, 2021
Hi @cdegroot,
Good afternoon.
Looking at the code, looks like it is an automated unit test code where your test data is real record from DynamoDB Streams. Could you please share the source for the JSON string? In you JSON string, the value for
ApproximateCreationDateTimeis1480642020000. However, the example at https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.Tutorial.html, has value1479499740for example. Notice the extra last 3 digits, as pointed by you as well. Not sure if there is an issue with your test data. While I didn't got a chance to examine the actual event received from DynamoDB stream, just wanted to validate your test data.Thanks,
Ashish
cdegroot commentedon Mar 24, 2021
I created that test based on real data I saw flowing so I could reproduce (and work around the issue). I won't share our full data in public, but hopefully the following exposition helps.
From another (JS-based) Kinesis consumer, which is logging full Kinesis events, I copied an event:
I snipped most of the payload for brevity and privacy, but base64 decoding it:
(again edited for brevity and privacy). As you can see, there's a 13 digit timestamp in there. I added three zeroes to the existing test data (which I think I snipped from here] to reproduce the issue.
ashishdhingra commentedon Apr 2, 2021
Hi @cdegroot,
Good afternoon.
Unfortunately I'm unable to reproduce the issue. Used the below steps:
HighScoresWithStreamwith:Username (String)as Primary partition key andGame (String)as Primary sort keyDynamoDB streamenabled (View type asNew and old images).csproj
Function.cs
aws-lambda-tools-defaults.json
{ "Information" : [ "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", "dotnet lambda help", "All the command line options for the Lambda command can be specified in this file." ], "profile" : "default", "region" : "us-east-2", "configuration" : "Release", "framework" : "netcoreapp3.1", "function-runtime" : "dotnetcore3.1", "function-memory-size" : 256, "function-timeout" : 30, "function-handler" : "DynamoDbStream_Issue839::DynamoDbStream_Issue839.Function::FunctionHandler", "function-name" : "StreamConsumer", "package-type" : "Zip", "function-role" : "arn:aws:iam::139480602983:role/lambda_exec_StreamConsumer-0", "tracing-mode" : "PassThrough", "environment-variables" : "", "image-tag" : "", "function-description" : "" }NOTE: To keep things simple for reproduction, the role
lambda_exec_StreamConsumer-0hasAWSLambdaExecuteandAmazonDynamoDBFullAccesspolicies attached.DynamoDBtrgigger for tableHighScoresWithStreamAs you could see from JSON captured above, the
ApproximateCreationDateTimehas value with 10 digits (not 13 digits).Please let me know if this helps.
Thanks,
Ashish
github-actions commentedon Apr 17, 2021
This issue has not recieved a response in 2 weeks. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
7 remaining items
Tragetaschen commentedon Mar 2, 2022
Shouldn't this be reopened and kept open then?
ashovlin commentedon Mar 10, 2022
Agreed, reopening.
It does appear that the service response may vary depending on context.
I think we may be able to either try to recognize that we're within a Kinesis context, or else DateTimeConverter could be expanded to handle both seconds and milliseconds as the original issue suggested.
Handle when Lambda events are sent unix epoch dates in milliseconds
Handle when Lambda events are sent unix epoch dates in milliseconds
ashishdhingra commentedon Apr 22, 2024
@cdegroot Good afternoon. The issue should be addressed as part of PR #1710. Could you please try upgrading to latest versions of
Amazon.Lambda.Serialization.JsonandAmazon.Lambda.Serialization.SystemTextJson, and verify if the issue is resolved?Thanks,
Ashish
github-actions commentedon Apr 24, 2024
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.