1

I have a problem with routing using API Gateway headers. I am using org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest as a handler request. I have two functions, they work locally. They work if I set environment variable.

If I use API Gateway headers (spring.cloud.function.definition:lowercase), I get:

{
  "errorMessage": "java.lang.NullPointerException",
  "errorType": "java.lang.NullPointerException",
  "stackTrace": [
    "org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateMessage(AWSLambdaUtils.java:123)",
    "org.springframework.cloud.function.adapter.aws.FunctionInvoker.handleRequest(FunctionInvoker.java:105)",
    "java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
    "java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)",
    "java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)",
    "java.base/java.lang.reflect.Method.invoke(Unknown Source)"
  ]
}

Example code reproducing the issue is here: https://github.com/cygi/cloudexample

POM is based on samples from Spring Cloud Function codebase (example code (https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-aws-routing). Spring Cloud Function version is 3.2.1 (sample had a SNAPSHOT version, that uses JAVA 11, which is not available in AWS Lambda, at least without docker).

Krzysztof Cygan
  • 310
  • 3
  • 9
  • 1
    Sorry, i don't even know where to begin. You provided stack trace fragment but nothing else. Which header you are using, how you are making a request, what version of spring-cloud-function you are using. Please update your question or even better . . make a small application that reproduces the issue and push it somewhere where we can take a look (e.g., GitHub) – Oleg Zhurakousky Feb 09 '22 at 14:16
  • @OlegZhurakousky thanks. I added an example code and a comment. I am pretty sure I am doing something incorrect there, but I got stuck on it. – Krzysztof Cygan Feb 09 '22 at 17:06

1 Answers1

1

Reverting to Spring Cloud Function 3.1.6 has resolved the problem.

Test event for AWS Lambda:

{
  "body": "foo",
  "httpMethod": "POST",
  "isBase64Encoded": false,
  "headers": {
      "spring.cloud.function.definition": "uppercase"
  }
}

Result on 3.2.2

{
  "statusCode": 417,
  "headers": null,
  "body": "Failed to establish route, since neither were provided: 'spring.cloud.function.definition' as Message header or as application property or 'spring.cloud.function.routing-expression' as application property."
}

Result on 3.1.6

{
  "isBase64Encoded": false,
  "headers": {
    "id": "758c1873-9377-25af-5ca2-84f55710ff2a",
    "contentType": "application/json",
    "timestamp": "1644500775689"
  },
  "body": "\"bbbb\"",
  "statusCode": 200
}
Krzysztof Cygan
  • 310
  • 3
  • 9