Skip to content

AWS Adapter: CustomRuntimeEventLoop sticks with first function definiton header when invoked  #1049

@ArnauAregall

Description

@ArnauAregall

Describe the bug

I have a Spring Cloud Function application deployed as an AWS Lamda on a provided.al2 Runtime (the application is a GraalVM native executable).

The Spring Boot and Spring Cloud dependencies I am using:

springBootVersion=3.1.0
springCloudVersion=2022.0.3
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.cloud:spring-cloud-function-context")
implementation("org.springframework.cloud:spring-cloud-function-web")
implementation("org.springframework.cloud:spring-cloud-function-adapter-aws")

The application exposes two different functions as @Beans:

@Bean
fun forecast(weatherService: WeatherService): (Message<GeoLocation>) -> Mono<Forecast> = weatherService::getForecast

@Bean
fun question(questionService: QuestionService): (Message<Question>) -> Mono<Answer> = questionService::answerQuestion

After deploying the AWS Lambda, I can correctly invoke the "question" function using HTTP message header spring.cloud.function.definition: question with a JSON request body that maps successfully as a Question domain object, and the application returns the desired response. Everything OK until here.

But after that, if I want to invoke the just theforecast function, now with the HTTP header spring.cloud.function.definition: forecast and corresponding request body message that can be mapped to a GeoLocation object, the CustomRuntimeEventLoop detects the resolved function is still question.

Therefore then the message conversion fails as it tries to convert the request body to a Question object with a body aimed for a GeoLocation object.

Evidences from CloudWatch logs (removed AWS account sensitive parts):

2023/06/19/[$LATEST]c646dfa4d77c49c3a462b769ebf7ebcf 2023-06-19T08:49:02.108000 2023-06-19T08:49:02.108Z  INFO 9 --- [pool-5-thread-1] o.s.c.f.a.aws.CustomRuntimeEventLoop     : Located function question
2023/06/19/[$LATEST]c646dfa4d77c49c3a462b769ebf7ebcf 2023-06-19T08:49:02.108000 2023-06-19T08:49:02.108Z  INFO 9 --- [pool-5-thread-1] o.s.c.f.adapter.aws.AWSLambdaUtils       : Received: {"version":"1.0","resource":"$default","path":"/","httpMethod":"POST","headers":{"Content-Length":"48","Content-Type":"application/json","Host":"XXXXXXXXXX.amazonaws.com","User-Agent":"Apache-HttpClient/4.5.14 (Java/17.0.6)","X-Amzn-Trace-Id":"Root=1-......","X-Forwarded-For":".......","X-Forwarded-Port":"443","X-Forwarded-Proto":"https","accept":"application/json","accept-encoding":"br,deflate,gzip,x-gzip","spring.cloud.function.definition":"forecast"},"multiValueHeaders":{"Content-Length":["48"],"Content-Type":["application/json"],"Host":["XXXXXXXXXX.amazonaws.com"],"User-Agent":["Apache-HttpClient/4.5.14 (Java/17.0.6)"],"X-Amzn-Trace-Id":["Root=1-6490167e-6b78cfea23bc44e72647d12b"],"X-Forwarded-For":["XXXXXXXXXX"],"X-Forwarded-Port":["443"],"X-Forwarded-Proto":["https"],"accept":["application/json"],"accept-encoding":["br,deflate,gzip,x-gzip"],"spring.cloud.function.definition":["forecast"]} ....}

2023/06/19/[$LATEST]c646dfa4d77c49c3a462b769ebf7ebcf 2023-06-19T08:49:02.109000 java.lang.IllegalStateException: Failed to convert. Possible bug as the conversion probably shouldn't have been attempted here
2023/06/19/[$LATEST]c646dfa4d77c49c3a462b769ebf7ebcf 2023-06-19T08:49:02.109000 at org.springframework.cloud.function.json.JacksonMapper.doFromJson(JacksonMapper.java:65) ~[na:na]
2023/06/19/[$LATEST]c646dfa4d77c49c3a462b769ebf7ebcf 2023-06-19T08:49:02.109000 at org.springframework.cloud.function.json.JsonMapper.fromJson(JsonMapper.java:66) ~[aws-lambda-spring-cloud-function:4.0.3]
2023/06/19/[$LATEST]c646dfa4d77c49c3a462b769ebf7ebcf 2023-06-19T08:49:02.109000 at org.springframework.cloud.function.adapter.aws.AWSTypesMessageConverter.convertFromInternal(AWSTypesMessageConverter.java:90)
...

Note: after waiting the lambda cooldown period, invoking again just the question function, it works correctly.

I am not sure if it could be somehow related to the heads up of the reference documentation, as I am using Mono<?> return types.

https://cloud.spring.io/spring-cloud-function/reference/html/spring-cloud-function.html#_function_routing

image

Disclaimer: did not try with a java17 runtime though.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions