question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Amazon.Lambda.KafkaEvents.KafkaEvent cannot be deserialized

See original GitHub issue

Description

The latest version of Amazon.Lambda.KafkaEvents.KafkaEvent cannot deserialize events when using SelfManagedKafka as source events.

Reproduction Steps

The hander function signature looks like

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
...
...
    public async Task FunctionHandler(KafkaEvent kafkaEvent, ILambdaContext context){...}

Logs

Error converting the Lambda event JSON payload to type Amazon.Lambda.KafkaEvents.KafkaEvent: The JSON value could not be converted to System.String. Path: $.records.TOPIC[0].partition | LineNumber: 0 | BytePositionInLine: 377.: JsonSerializerException at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream) at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, Utf8JsonReader& reader, Exception ex) at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack) at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader) at System.Text.Json.JsonSerializer.ParseCore(ReadOnlySpan1 utf8Json, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan1 utf8Json, JsonSerializerOptions options) at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream) Cannot get the value of a token type ‘Number’ as a string.: InvalidOperationException at System.Text.Json.Utf8JsonReader.GetString() at System.Text.Json.Serialization.Converters.JsonConverterString.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) at System.Text.Json.JsonPropertyInfoNotNullable`4.OnRead(ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.JsonPropertyInfo.Read(JsonTokenType tokenType, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)

Environment

Resolution

I noticed that there has been a change to the type Partition property - used to be int now is string. Any reason for that? https://github.com/aws/aws-lambda-dotnet/blame/b49dfae373538aad2811340cd2a03b478cb59318/Libraries/src/Amazon.Lambda.KafkaEvents/KafkaEvent.cs#L46


Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ashishdhingracommented, Mar 24, 2022

Got confirmation from service team that partition should be modeled as int. They will work to update the documentation (cannot share the ETA):

We would work in fixing this in Amazon.Lambda.KafkaEvents package.

1reaction
ganeshnjcommented, Feb 3, 2022

@gabriel-myob It seems there is inconsistency between the payload you are receiving (partition is int) and docs (partition is string).

I quickly checked Java code, and they appear to model partition as int as well.

This should be an easy fix but we should make sure it works with a real Kafka event.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Can not deserialize instance of java.lang.String out ...
This is an error message during Lambda deserialization. ... the error comes up because the JSON request cannot be casted to a String...
Read more >
Deserializes Kafka events using schema in AWS Glue ...
AWS Lambda function that deserializes events in a Kafka topic using Avro schema in AWS Glue Schema Registry. This code example shows how...
Read more >
Using Lambda with self-managed Apache Kafka
After creating a Kafka event source mapping with the consumer group ID specified, you cannot update this value. Adding a self-managed Kafka cluster...
Read more >
Using Lambda with Amazon MSK
The consumer group ID that you specify must be unique among all your Kafka event sources. After creating a Kafka event source mapping...
Read more >
AWS Lambda function errors in Java
In the following example, the runtime fails to deserialize the event into an object. The input is a valid JSON type, but it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found