I've a simple Micronaut AWS lambda request handled using the micronaut-function-aws functionality.
The service that I inject doesn't seem to be created when it's run in AWS.
If I do the whole groovy script function handler and use @Field @Singleton TestService testService it seems to work fine when running locally.
Any idea what I'm doing wrong?
Service:
package testtest
import groovy.transform.CompileStatic
@CompileStatic
@Singleton
class TestService {
String test = "Test"
}
handler:
package testtest
import com.amazonaws.services.lambda.runtime.Context
import io.micronaut.function.aws.MicronautRequestStreamHandler
import javax.inject.Inject
class TestHandler extends MicronautRequestStreamHandler {
@Inject TestService testService
@Override
protected void execute(InputStream input, OutputStream output, Context context) throws IOException {
output << testService.test
}
}
Stack trace from AWS lambda
Cannot get property 'test' on null object: java.lang.NullPointerException
java.lang.NullPointerException: Cannot get property 'test' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:304)
at testtest.TestHandler.execute(TestHandler.groovy:14)
at testtest.TestHandler.execute(TestHandler.groovy)
at io.micronaut.function.aws.MicronautRequestStreamHandler.handleRequest(MicronautRequestStreamHandler.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)