I have a function that needs to run on lambda taking an SQSEvent as input. What i see is that, the FunctionInvoker is able to detect the function, but the apply method is not invoked. What might be the issue with configuration here?
MyApplication.java
@SpringBootConfiguration
@EnableFeignClients
public class MyApplication implements ApplicationContextInitializer<GenericApplicationContext> {
public static void main(String[] args) {
// SpringApplication.run(MyApplication.class, args);
}
@Override
public void initialize(GenericApplicationContext context) {
context.registerBean("myFunction", FunctionRegistration.class,
() -> new FunctionRegistration<>(new MyFunction()).type(FunctionTypeUtils.functionType(SQSEvent.class, String.class)));
}
}
MyFunction.java
@Slf4j @Data
public class MyFunction implements Function<SQSEvent, String> {
@Override
public String apply(SQSEvent sqsEvent) {
log.info("Received event: " + sqsEvent);
doSomething();
return "success";
}
}
template.yaml
MyLambdaService:
Type: AWS::Serverless::Function
Properties:
CodeUri: ...
Handler: org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest
....
Environment:
Variables:
FUNCTION_NAME: myFunction
MAIN_CLASS: com.myorg.my_service.MyApplication
The logs I get: (both in sam local invoke as well as deployed lambda)
2023-06-26 14:09:55 INFO AWSLambda - Started AWSLambda in 38.986 seconds (process running for 101.709)
2023-06-26 14:09:55 INFO FunctionInvoker - Locating function: 'null'
2023-06-26 14:09:55 INFO FunctionInvoker - Located function: 'myFunction'
2023-06-26 14:09:55 a77f799b-0a4a-4311-b9b7-74bd6c963c6f INFO AWSLambdaUtils - Received: { ...test event content ...}
END RequestId: a77f799b-0a4a-4311-b9b7-74bd6c963c6f
REPORT RequestId: a77f799b-0a4a-4311-b9b7-74bd6c963c6f Init Duration: 0.16 ms Duration: 109589.64 ms Billed Duration: 109590 ms Memory Size: 512 MB Max Memory Used: 512 MB