micronaut-projects / micronaut-aws

Projects specific to integrating Micronaut and Amazon Web Services (AWS)
Apache License 2.0
83 stars 81 forks source link

S3EventNotificationRecord not deserialized correctly #1966

Closed mwullink closed 7 months ago

mwullink commented 7 months ago

Expected Behavior

expect a complete S3EventNotification containing the s3 create object event

package example.micronaut;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification;

import io.micronaut.function.aws.MicronautRequestHandler;
import io.micronaut.serde.annotation.Serdeable;

@Serdeable
public class FunctionRequestHandler extends MicronautRequestHandler<S3EventNotification, Void> {

    private static final Logger LOG = LoggerFactory.getLogger(FunctionRequestHandler.class);

    @Override
    public Void execute(S3EventNotification input) {

        LOG.info("event: " + input);

        for (S3EventNotification.S3EventNotificationRecord record : input.getRecords()) {

            if (record.getEventName().contains("ObjectCreated")) {
                String key = record.getS3().getObject().getKey();
                LOG.info("key: " + key);
            }

        }

        return null;
    }

}

Actual Behaviour

The S3EventNotification does not contain any S3EventNotificationRecord instances, the list is null and causing a NPE

java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because the return value of "com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification.getRecords()" is null
    at example.micronaut.FunctionRequestHandler.execute(FunctionRequestHandler.java:30)
    at example.micronaut.FunctionRequestHandler.execute(FunctionRequestHandler.java:1)
    at io.micronaut.function.aws.MicronautRequestHandler.handleRequest(MicronautRequestHandler.java:110)

Steps To Reproduce

use provided example from: https://guides.micronaut.io/latest/micronaut-aws-lambda-s3-event-gradle-java.html

Environment Information

Maven Java 17 and 21

Example Application

No response

Version

4.2.0

mwullink commented 7 months ago

this is a duplicate of: #1940