spring-cloud / spring-cloud-function

Apache License 2.0
1.04k stars 616 forks source link

FunctionRoute is working local but not in aws lambda and api gateway #698

Closed jaganm2018 closed 3 years ago

jaganm2018 commented 3 years ago

Issue: functionRoute is working locally but not in AWS lambda and apigateway.

Description: Done sample code with below version , implemented with upperCase and lowerCase functions and tested locallly with http://local host:8080/functionRoute and Passing spring.cloud.function.defenation = {function_name} working fine.

Build exclude spring-web and deployed in to AWS lambda.

handler: SpringBootAwsRequestHandler scenario1: function_name: lowerCase Tested through apiGateway .. it’s working fine.

scenario2: function_name: functionRoute Tested through apiGateway and passed spring.cloud.function.defenation: lowerCase

exception: no function name found.

versions: Spring-cloud : 2020.0.2 Spring cloud aws - 3.1.2 Spring boot : 2.4.3 Spring-web : 3.x

can you help me what’s mistake I did? if possible, can you please share the any sample cloud function with multi handle in aws lambda and apiGateway.

thanks in advance for helping me.

olegz commented 3 years ago

Isn't this the same issue - https://github.com/spring-cloud/spring-cloud-function/issues/686

Please provide more information (e..g, sample code) similar to the previous reporter

jaganm2018 commented 3 years ago

it’s not related to 686 issue. Local it’s working fine with functionRouter but is not working in AWS apiGateway.

please see below steps:

Step-1 : Implemented below spring function in demo spring boot application..

@Bean Public Function<String,String> reverseString() { return value -> new StringBuffer(value).toUppeecase(); }

Local test scenarios :

Locally, it’s working.. please see below Test scenarios ...

Test-1: direct function URL Input: world Url: http://local host:8089/reverseString Output: dlrow

Test 2: functionRouter URL Input : world Url: http://local host:8080/functionRoute Headers: spring.cloud.function.defenation: reverseString Output: dlrow

Step-2: deployed into AWS lambda and api gateway

a) Now same application deployed into AWS lambda with below configuration

b)Handler: org.springframework.cloud.function.adapater.aws.SpringBootStreamHabdler

c) Environment: FUNCTION_NAME: reverseFunction d) ran lambda test , running successfully and result is dlrow with input : world

Step-3: created apiGateway and testing a) created apiGateway and run the testcase : running successfully and output is dlrow with input : world

Step-4: running with Integrate proxy AWS gateway a) changed the integration request to proxy in aws gateway and ran the test case .. b) after ran the testcase with input world.. then got internal server error.. Can’t convert event stream .. it seems, request body is going empty to stream handler. c) same error replicated in Step-3 with empty input request.

Step-5: Same step-3 and changed the lambda environment FUNCTION_NAME to functionRoute

a) changed the function name to functionRoute b) passed the spring.cloud.function.defenation: reverseString c) getting error as Routing input of type publisher is not supported per individual values (e.g., message header or POJO). Instead you should use ‘spring.cloud.function.definition’ or spring.cloud.function.routing-expression’ as application properties.

Hope , covered all scenarios and my function name. Soon I will create project and provide you.

Please let me know if you need any more information.

olegz commented 3 years ago

Actually there are indeed issues with routing feature. So I am addressing it and will provide detailed documentation and sample with instructions

jaganm2018 commented 3 years ago

Thanks olegz for replying and providing with sample and details document in advance.

Please see below my git repo for reference of my code. https://github.com/jaganm2018/spring-cloud-function-aws

please let me know if you need any more information.

jaganm2018 commented 3 years ago

Hi,any updates?

olegz commented 3 years ago

Perfect timing as I just pushed some changes. The snapshots should be available in about 15-20 min. There is also a new example with details instructions - https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-aws-routing as well as the documentation updates.

In the nutshell. . .

I am keeping the issue open for few days, to polish few more things and also hoping to get some feedback. Keep in mind that we will be releasing 3.1.3 next Tuesday, so would be nice to have a feedback before that.

Thank you for your patience.

jaganm2018 commented 3 years ago

Very nice and thanks a lot for providing all the details.. let me go through it and will get back to you

olegz commented 3 years ago

Snapshots should be available now

jaganm2018 commented 3 years ago

Got it..May I know exact release date.

olegz commented 3 years ago

Release is most likely this Wednesday

olegz commented 3 years ago

I am resolving this issue since everything has been addressed documentation and sample provided. Feel free to raise a new issue if you believe something is missing