spring-cloud-function icon indicating copy to clipboard operation
spring-cloud-function copied to clipboard

Unable to route to functions on AWS API Gateway (REST API)

Open sayadi opened this issue 4 years ago • 5 comments

Describe the bug Sending the spring.cloud.function.definition header to the API Gateway has no effect on routing, I still get the error:

2021-12-21 11:33:49.936 ERROR 8 --- [           main] o.s.c.f.adapter.aws.FunctionInvoker      : java.lang.IllegalStateException: 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.

Setting the spring_cloud_function_definition as an environment variable on Lambda does work though.

Sample I'm testing with the provided function-sample-aws-routing as is. Using Maven.

I've added this serverless.yml to deploy the Lambda and API Gateway:

service: spring-cloud-function-sample
provider:
  name: aws
  runtime: java11
  region: ap-southeast-1
  stage: predev
  timeout: 10
  lambdaHashingVersion: 20201221
package:
  artifact: target/function-sample-aws-routing-2.0.0.RELEASE-aws.jar
functions:
  api:
    handler: org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest
    events:
    - httpApi: '*'

The steps to reproduce are roughly: 1- clone this repository 2- change directory to spring-cloud-function-samples/function-sample-aws-routing 3- mvn clean package 4- Add the serverless.yml file and run: sls deploy 5- curl -X POST https://xxxxxxxxxxx.execute-api.ap-southeast-1.amazonaws.com -H "spring.cloud.function.definition: uppercase" -H "Content-Type: application/json" -d '"foo"'

Result: {"message":"Internal Server Error"}

Expected: FOO

Error on Lambda from CloudWatch:

2021-12-21 11:33:49.936 ERROR 8 --- [           main] o.s.c.f.adapter.aws.FunctionInvoker      : java.lang.IllegalStateException: 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.

sayadi avatar Dec 21 '21 12:12 sayadi

Yes indeed we have an issue

olegz avatar Jan 03 '22 11:01 olegz

Thanks, Oleg for the confirmation.

sayadi avatar Jan 03 '22 17:01 sayadi

I am almost done with it, This is a regression from the previous improvements. Will push tomorrow

olegz avatar Jan 03 '22 17:01 olegz

@sayadi I am now assuming that you are only having this problem with 3.2 version. Correct? Bacause I just tested it with 3.1.6 and all is good, so I'll remove the backport label and merg

olegz avatar Jan 04 '22 09:01 olegz

@olegz Indeed! Setting the version to 3.1.6 on the spring-cloud-function-adapter-aws dependency works:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-adapter-aws</artifactId>
            <version>3.1.6</version>
        </dependency>

This alone unblocks us!

Will test with the latest push and update you as well.

sayadi avatar Jan 04 '22 10:01 sayadi