Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Context is coming as null [message.getHeaders().get(AWSLambdaUtils.AWS_CONTEXT, Context.class)] #1187

Open
jpOlivo-uala opened this issue Oct 1, 2024 · 3 comments

Comments

@jpOlivo-uala
Copy link

jpOlivo-uala commented Oct 1, 2024

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 [email protected]/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 [email protected]/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(<generated>)\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 [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat [email protected]/java.lang.Thread.runWith(Thread.java:1596)\n\tat [email protected]/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"
> }

@olegz olegz added the AWS label Oct 2, 2024
olegz added a commit that referenced this issue Oct 24, 2024
olegz added a commit that referenced this issue Oct 24, 2024
@olegz
Copy link
Contributor

olegz commented Oct 24, 2024

Can you please test it with 4.1.4-SNAPSHOT and see if Context comes in as null? I just added a log (warn).
I am wondering if somehow natively Context is not coming thru

@jpOlivo-uala
Copy link
Author

I tested it with 4.1.4-SNAPSHOT and also enable org.springframework.cloud.function.adapter.aws: DEBUG however nothing is written on the logs

@olegz olegz added this to the 4.2.1 milestone Dec 17, 2024
@olegz
Copy link
Contributor

olegz commented Dec 18, 2024

Can you please provide a reproducible sample as I can not reproduce it and i can see the Context with all versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants