5

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!";
    }
}
simon
  • 559
  • 1
  • 6
  • 19
  • your implementation looks correct. have you tried it? the name of the function bean must be present in `application.yml` as `micronaut.function.name` (done by default when you generate function from CLI) – musketyr Apr 01 '19 at 09:20

1 Answers1

1

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!";
    }
}
Traycho Ivanov
  • 2,887
  • 14
  • 24