镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

AWS Lambda Environment fails to find S3EventNotification** class. Works locally #262

Description

@flipch

try {
// Try to load newer version of S3EventNotification from aws-lambda-java-events v3+
Class eventNotificationRecordClass = SerializeUtil.loadCustomerClass(
S3_EVENT_NOTIFICATION_CLASS_V3 + "$S3EventNotificationRecord", classLoader);
jsonObject = serializeEvent(eventNotificationRecordClass, value, S3_EVENT_NOTIFICATION_CLASS_V3);
} catch (Exception ex) {
// Fallback to aws-lambda-java-events pre-v3 (relies on aws-s3-sdk)
Class eventNotificationRecordClass = SerializeUtil.loadCustomerClass(
S3_EVENT_NOTIFICATION_CLASS_V2 + "$S3EventNotificationRecord", classLoader);
jsonObject = serializeEvent(eventNotificationRecordClass, value, S3_EVENT_NOTIFICATION_CLASS_V2);
}

Something seems to be failing here when trying to find the com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification** classes as my lambda clearly has them available. I've exported from the AWS Console and extracted the jar file.

image

Yet I still get a runtime error when attempting to deserialize a string into an S3Event

java.lang.ClassNotFoundException: com.amazonaws.services.s3.event.S3EventNotification$S3EventNotificationRecord: com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil$ReflectException
com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil$ReflectException: java.lang.ClassNotFoundException: com.amazonaws.services.s3.event.S3EventNotification$S3EventNotificationRecord
        at com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil.loadClass(ReflectUtil.java:85)
        at com.amazonaws.services.lambda.runtime.serialization.util.SerializeUtil.loadCustomerClass(SerializeUtil.java:37)
        at com.amazonaws.services.lambda.runtime.serialization.events.serializers.S3EventSerializer.deserializeEvent(S3EventSerializer.java:157)
        at com.amazonaws.services.lambda.runtime.serialization.events.serializers.S3EventSerializer.fromJson(S3EventSerializer.java:93)

Or when instantiating an deserializer for S3EventNotificationRecord

java.lang.ClassNotFoundException: org.joda.time.DateTime: com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil$ReflectException
com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil$ReflectException: java.lang.ClassNotFoundException: org.joda.time.DateTime
        at com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil.loadClass(ReflectUtil.java:85)
        at com.amazonaws.services.lambda.runtime.serialization.util.SerializeUtil.loadCustomerClass(SerializeUtil.java:37)
        at com.amazonaws.services.lambda.runtime.serialization.events.modules.DateTimeModule.<init>(DateTimeModule.java:28)
        at com.amazonaws.services.lambda.runtime.serialization.events.LambdaEventSerializers.serializerFor(LambdaEventSerializers.java:248)
        ```

Activity

  1. changed the title [-]AWS Lambda Environment fails to find class. Works locally[/-] [+]AWS Lambda Environment fails to find S3EventNotification** class. Works locally[/+] on Jul 26, 2021
  2. flipch commented on Jul 26, 2021

    @flipch
    Author

    The issue seems to revolve around the lambda's environment class loader not functioning properly.

    The solution was to change the passed in class loader, i.e from
    this.s3EventSerializer = LambdaEventSerializers.serializerFor(S3EventNotification.class, ClassLoader.getSystemClassLoader();
    to
    this.s3EventSerializer = LambdaEventSerializers.serializerFor(S3EventNotification.class, Thread.currentThread().getContextClassLoader());

  3. kedarundale17 commented on Feb 4, 2022

    @kedarundale17

    @flipch I faced the same issue , the above mentioned solution works like a charm.
    Thanks

  4. marczis commented on Nov 16, 2023

    @marczis

    Hello, I'm not supposed to see this in 2023 right? Or.... :)

  5. shinusuresh commented on Jan 4, 2024

    @shinusuresh

    2024 yey

  6. fezekilePlaatyiAbsa commented on Jul 1, 2025

    @fezekilePlaatyiAbsa

    2025 yey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions