Repository navigation
AWS Lambda Environment fails to find S3EventNotification** class. Works locally #262
Copy link
Copy link
Closed
Description
Lines 103 to 114 in 3ab2213
| 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.
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)
```
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

Activity
[-]AWS Lambda Environment fails to find class. Works locally[/-][+]AWS Lambda Environment fails to find S3EventNotification** class. Works locally[/+]flipch commentedon Jul 26, 2021
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());kedarundale17 commentedon Feb 4, 2022
@flipch I faced the same issue , the above mentioned solution works like a charm.
Thanks
marczis commentedon Nov 16, 2023
Hello, I'm not supposed to see this in 2023 right? Or.... :)
shinusuresh commentedon Jan 4, 2024
2024 yey
fezekilePlaatyiAbsa commentedon Jul 1, 2025
2025 yey