Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS lambda extension fails to Deserialize trigger Classes correctly #14513

Open
StefanVanDyck opened this issue Jan 22, 2021 · 9 comments
Open
Labels
area/amazon-lambda kind/bug Something isn't working

Comments

@StefanVanDyck
Copy link

StefanVanDyck commented Jan 22, 2021

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 of java.util.Date out 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):

  • AWS lambda
@StefanVanDyck StefanVanDyck added the kind/bug Something isn't working label Jan 22, 2021
@ghost ghost added the area/amazon-lambda label Jan 22, 2021
@ghost
Copy link

ghost commented Jan 22, 2021

/cc @matejvasek, @patriot1burke

@StefanVanDyck
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

StefanVanDyck commented Jan 22, 2021

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
Copy link

Issue still exists on Quarkus 1.12.0

@cherrydev
Copy link

Issue still exists in Quarkus 2.1.1

@goranopacic
Copy link

new version, V4, of Events library is coming aws/aws-lambda-java-libs#282

@nicklasweasel
Copy link

nicklasweasel commented Jan 25, 2024

Issue still exists in Quarkus 3.6.7

@geoand
Copy link
Contributor

geoand commented Sep 20, 2024

@patriot1burke ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/amazon-lambda kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants