How to create a micronaut AWS Lambda function triggered using an S3Event?

Viewed 748

I looked at the micronaut documentation at https://docs.micronaut.io/latest/guide/index.html#functionBean and all examples assume events are coming from API Gateway and the request body is sent out as a POJO. Can Micronaut also support S3Event and all other AWS Lambda event types for it's serverless functions? Example: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html#with-s3-example-deployment-pkg-java

Can something like the below be supported? I didn't find how java Functions are mapped to RequestHandler<S3Event, String> that AWS typically expects in Micronaut.

package example;

import io.micronaut.function.FunctionBean;
import java.util.function.Consumer;

@FunctionBean("hello-world-java")
public class HelloJavaFunction implements Function<S3Event, String> {

    @Override
    public String apply(S3Event) { 
        return "Hello world!";
    }
}
1 Answers

It could be done also using MicronautRequestHandler.


@FunctionBean("hello-world-java)
public class HelloJavaFunction extends MicronautRequestHandler<S3Event, String> {

    @Override
    public String execute(final S3Event event) {
        return "Hello world!";
    }
}
Related