0

Is it possible to access to query parameters that are forwarded from aws apigateway to awslamdba implemented using spring cloud function. the following is my implementation. I call this using http get request

example: http://sampledomain.com/test?param1=value

How can I retrieve param1 value in the method below

@Bean    
public Function<Message<String>,String> reverseString2() {      
    return value1 -> {              
          System.out.println("headers..."+value1.getHeaders());           
          value1.getHeaders().entrySet().forEach(entry -> System.out.println(entry.getKey() + " - " + entry.getValue()));             
          return "example";
    } ;
}
  • It should be in headers. Are you saying it is not? What version of s-c-function you are using? – Oleg Zhurakousky Mar 04 '22 at 14:52
  • it is pulling 3.2.x and the spring cloud version i am using is 2021.0.1 the below is my pom org.springframework.boot spring-boot-starter-parent 2.6.4 org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import – user16668777 Mar 04 '22 at 15:04
  • Than it should be in headers. Is it not? – Oleg Zhurakousky Mar 04 '22 at 15:07
  • when i use the below I am getting the path parameters. @Bean public Function reverseString1() { return value1 -> { System.out.println("headers..." + value1.getHeaders()); System.out.println("paylaod..." + value1.getPathParameters()); return "sample"; }; } – user16668777 Mar 04 '22 at 15:09
  • not sure what i am missing.. the following are the headers from my cloudwatch logs – user16668777 Mar 04 '22 at 15:14
  • headers...{Accept=*/*, User-Agent=PostmanRuntime/7.29.0, X-Forwarded-Proto=https, Host=sample.amazonaws.com, Accept-Encoding=gzip, deflate, br, X-Forwarded-Port=443, X-Amzn-Trace-Id=Root=1-62222c8a-57b869000c13c60c6582a823, X-Forwarded-For=71.135.203.35, aws-api-gateway=true, Postman-Token=0b9704a3-b30f-4894-9071-a4d1ba3620de, id=40f0d0a2-effe-d722-47f9-2a3c5e55657e, Content-Type=application/json, timestamp=1646406794522} – user16668777 Mar 04 '22 at 15:14
  • I do not see query parameters. but I notice it as part of events 2022-03-04 15:13:14.520 INFO 9 --- [ main] o.s.c.f.adapter.aws.FunctionInvoker : Received:... "queryStringParameters": { "test": "test1" }, – user16668777 Mar 04 '22 at 15:21
  • If I set handler to SpringBootApiGatewayRequestHandler then I get access to querystringparameters not if I use functioninvoker. But SpringBootApiGatewayRequesthandler is deprecated. – user16668777 Mar 04 '22 at 19:21
  • I must be missing something as I can not reproduce it, so I need a reproducible sample as I can clearly see headers are being propagated. You can create a bare minimum sample, push it to github so we can take a look – Oleg Zhurakousky Mar 08 '22 at 11:48
  • ok sure.. I am able to get headers.. but not able to see query parameters in those headers. I notice that in aws apigateway those in differnt section(as part of event) – user16668777 Mar 11 '22 at 14:14

1 Answers1

0

I don't think the Message supports the Query Parameters. You can try either of the options -

  1. Change your Function to Function<APIGatewayProxyRequestEvent, Message<String>> and then you can access the query parameters using apiGatewayProxyRequestEvent.getQueryStringParameters()
  2. If you want to use Function<Message<String>, Message<String>> , you can change the HttpMethod to POST and send the message in the Request body. Message.getPayload() will provide you with the content.
rhlarora84
  • 67
  • 6