AWS Context is coming as null [message.getHeaders().get(AWSLambdaUtils.AWS_CONTEXT, Context.class)]
jpOlivo-uala opened this issue · 2 comments
Describe the bug
Version
spring-cloud-function-adapter-aws - 4.1.2
AWS Context is coming as null from header. As mentioned in the document application was expecting context from Message header.
ex:
public class SimpleFunction implements Function<Message<String>, String> {
public String apply(Message<String> s) {
Context c = s.getHeaders().get(AWSLambdaUtils.AWS_CONTEXT, Context.class);
log.info(c.getInvokedFunctionArn());
// context is coming as null
}
}
I found this issue reported but it seems was fixed on 4.0.2 however in 4.1.2 the problem is present. My function run as native image with graalvm 21.0.2
Error Stacktrace:
{
"errorType": "NullPointerException",
"errorMessage": null,
"stackTrace": "java.lang.NullPointerException\n\tat com.example.demo.SimpleFunction.apply(SimpleFunction.java:36)\n\tat java.base@21.0.2/java.lang.reflect.Method.invoke(Method.java:580)\n\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:354)\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\n\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)\n\tat io.micrometer.observation.aop.ObservedAspect.lambda$observe$2(ObservedAspect.java:151)\n\tat io.micrometer.observation.Observation.observeChecked(Observation.java:600)\n\tat io.micrometer.observation.aop.ObservedAspect.observe(ObservedAspect.java:151)\n\tat io.micrometer.observation.aop.ObservedAspect.observeMethod(ObservedAspect.java:129)\n\tat java.base@21.0.2/java.lang.reflect.Method.invoke(Method.java:580)\n\tat org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637)\n\tat org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:627)\n\tat org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:71)\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720)\n\tat com.example.demo.SimpleFunction$$SpringCGLIB$$0.apply()\n\tat org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeFunctionAndEnrichResultIfNecessary(SimpleFunctionRegistry.java:974)\n\tat org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeFunction(SimpleFunctionRegistry.java:920)\n\tat org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:756)\n\tat org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:592)\n\tat org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop.eventLoop(CustomRuntimeEventLoop.java:145)\n\tat org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop.lambda$run$0(CustomRuntimeEventLoop.java:90)\n\tat java.base@21.0.2/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base@21.0.2/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base@21.0.2/java.lang.Thread.runWith(Thread.java:1596)\n\tat java.base@21.0.2/java.lang.Thread.run(Thread.java:1583)\n\tat org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)\n\tat org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)\n"
}