quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.75k stars 2.67k forks source link

AWS lambda extension fails to Deserialize trigger Classes correctly #14513

Open StefanVanDyck opened 3 years ago

StefanVanDyck commented 3 years ago

Describe the bug When running my DynamoDB-stream triggered lambda I receive the following error: 2021-01-21 01:37:10,665 ERROR [io.qua.ama.lam.run.AbstractLambdaPollLoop] (Lambda Thread) Failed to run lambda: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance ofjava.util.Dateout of VALUE_NUMBER_FLOAT token at [Source: (sun.net.www.protocol.http.HttpURLConnection$HttpInputStream); line: 1, column: 196] (through reference chain: com.amazonaws.services.lambda.runtime.events.DynamodbEvent["Records"]->java.util.ArrayList[0]->com.amazonaws.services.lambda.runtime.events.DynamodbEvent$DynamodbStreamRecord["dynamodb"]->com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord["ApproximateCreationDateTime"]) ... at io.quarkus.amazon.lambda.runtime.AbstractLambdaPollLoop$1.run(AbstractLambdaPollLoop.java:78)

This happens because AWS passes unix timestamps as a float value with milliseconds after the decimal point.

My handleRequest method looks like this: public LambdaResponse handleRequest(com.amazonaws.services.lambda.runtime.events.DynamodbEvent trigger, Context context)

I am using a native build(GraalVM), not sure if that matters.

Expected behavior I expect the lambda to be trigger using a Strongly-Type Java Object as event.

Actual behavior The lambda Crashes with a jackson Deserialization error.

To Reproduce

Will provide reproducer.

Steps to reproduce the behavior:

  1. Create a simple quarkus lambda project with a DynamoDB event in the handler method
  2. Deploy using dynamodb-stream trigger
  3. Put an item in the dynamodb table

Configuration

        <commons-lang3.version>3.11</commons-lang3.version>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <cucumber.version>6.9.1</cucumber.version>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus-plugin.version>1.11.0.Final</quarkus-plugin.version>
        <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
        <quarkus.platform.version>1.11.0.Final</quarkus.platform.version>
        <unirest.version>3.11.10</unirest.version>
        <java-jwt.version>3.12.0</java-jwt.version>
        <javafaker.version>1.0.2</javafaker.version>
        ...
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-amazon-lambda</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-mutiny</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-test-amazon-lambda</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-kafka-client</artifactId>
        </dependency>

Environment (please complete the following information):

ghost commented 3 years ago

/cc @matejvasek, @patriot1burke

StefanVanDyck commented 3 years ago

Forgot to mention the work around was to add a custom Date Deserializer to quarkus. This was easily achieved using an ObjectMapperCustomizer and copying the logic from com.amazonaws.services.lambda.runtime.serialization.events.modules.DateModule.

It just seems like this should work out-of-the-box when using the aws lambda extension.

patriot1burke commented 3 years ago

You are not using the quarkus dynamo extension correct? I agree this should work out of the box. We're having a bit of problem with deserializing AWS event types. They all seem to follow a different pattern. Some of the classes don't have setter methods, and it looks like others like dynamo do different date serialization.

StefanVanDyck commented 3 years ago

lambda-deserializer-reproducer.tar.gz

Indeed, I am not using the dynamo extension. I included a small reproducer starting from the lambda maven archetype with no additions.

It has 2 "integration" tests that mimick the behaviour on AWS.

TheGeekPharaoh commented 3 years ago

Issue still exists on Quarkus 1.12.0

cherrydev commented 3 years ago

Issue still exists in Quarkus 2.1.1

goranopacic commented 2 years ago

new version, V4, of Events library is coming https://github.com/aws/aws-lambda-java-libs/issues/282

nicklasweasel commented 9 months ago

Issue still exists in Quarkus 3.6.7

geoand commented 1 month ago

@patriot1burke ^