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

S3 lambda events can't be deserialized (and therefore tutorial fails) #2048

Closed
brucej72 opened this issue Feb 9, 2024 · 1 comment
Closed
Labels
info: workaround available A workaround is available for the issue

Comments

@brucej72
Copy link

brucej72 commented Feb 9, 2024

Expected Behavior

The tutorial here: https://guides.micronaut.io/latest/micronaut-aws-lambda-s3-event-maven-java.html
...should be able to be followed and run without error.

Note this issue looks like it was explored in #1941 but this does not appear to be fixed.

Actual Behaviour

The function handler is called, but throws an exception:

An error occurred during JSON parsing: java.lang.RuntimeException java.lang.RuntimeException: An error occurred during JSON parsing Caused by: io.micronaut.core.beans.exceptions.IntrospectionException: No deserializable introspection present for type: ResponseElementsEntity responseElements. Consider adding Serdeable.Deserializable annotate to type ResponseElementsEntity responseElements. Alternatively if you are not in control of the project's source code, you can use @SerdeImport(ResponseElementsEntity.class) to enable deserialization of this type. at io.micronaut.serde.support.DefaultSerdeIntrospections.resolveIntrospectionForDeserialization(DefaultSerdeIntrospections.java:196) at io.micronaut.serde.support.DefaultSerdeIntrospections.getDeserializableIntrospection(DefaultSerdeIntrospections.java:160) at io.micronaut.serde.support.deserializers.ObjectDeserializer.createDeserBean(ObjectDeserializer.java:133) at io.micronaut.serde.support.deserializers.ObjectDeserializer.lambda$getDeserializableBean$1(ObjectDeserializer.java:123) at io.micronaut.core.util.SupplierUtil$2.get(SupplierUtil.java:79) at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:124) at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69) at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592) at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476) at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432) at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412) at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125) at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69) at io.micronaut.serde.support.deserializers.collect.CoreCollectionsDeserializers$SpecificOnlyCollectionDeserializer.createSpecific(CoreCollectionsDeserializers.java:334) at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592) at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476) at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432) at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412) at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125) at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69) at io.micronaut.serde.jackson.JacksonJsonMapper.readValue0(JacksonJsonMapper.java:175) at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:169) at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:206) at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:70)

Steps To Reproduce

Using mn 4.2.4 (as per the tutorial) or 4.3.0 installed using sdk.

  1. Follow the tutorial linked above (you don't need to actually implement the thumbnail generator, just implement a trivial handler such as:
@Serdeable
public class FunctionRequestHandler extends MicronautRequestHandler<S3EventNotification, Void> {
	
    private static final Logger LOG = LoggerFactory.getLogger(FunctionRequestHandler.class);
	
	@Inject
	JsonMapper objectMapper;

	@Inject
	public S3Client s3;

	@Override
	public Void execute(S3EventNotification input) {

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

			LOG.info("event name: {}", record.getEventName());
			
		}

		return null;
	}
}
  1. Copy a file into the S3 bucket you have set up with the lambda event handler
  2. Look at the Cloudwatch logs

Environment Information

MacOS 14.3
java 17.0.8 2023-07-18 LTS
mn 4.2.4 or 4.3.0

Example Application

No response

Version

4.2.4 or 4.3.0

@sdelamo sdelamo added the info: workaround available A workaround is available for the issue label Mar 8, 2024
sdelamo added a commit that referenced this issue Mar 8, 2024
@sdelamo
Copy link
Contributor

sdelamo commented Mar 8, 2024

Thanks for reporting @brucej72 We have an issue which we are currently investigating:

#2079

A workaround is to use Micronaut Jackson Databind.

I wrote a CDK sample to test this https://github.com/sdelamo/micronaut-aws-lambda-s3-cdk

sdelamo added a commit that referenced this issue Mar 8, 2024
Add a CustomPojoSerializer implementation which includes the package io.micronaut.aws.lambda.events.serde. This package contains `@SerdeImport` for the AWS Lambda Events classes.

Close: #2048
sdelamo added a commit that referenced this issue Mar 8, 2024
Add a CustomPojoSerializer implementation which includes the package io.micronaut.aws.lambda.events.serde. This package contains `@SerdeImport` for the AWS Lambda Events classes.

Close: #2048
@sdelamo sdelamo closed this as completed in 9cd35ec Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info: workaround available A workaround is available for the issue
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants