0

I am building a AWS lambda function using Spring cloud, aws adapter and spring native. The lambda is fronted by a APIGateway HTTP API V2.0.

     <java.version>11</java.version>
    <spring-cloud.version>2021.0.2</spring-cloud.version>
    <spring-native.version>0.11.4</spring-native.version>
    <aws-lambda-events.version>3.9.0</aws-lambda-events.version>
    <wrapper.version>1.0.27.RELEASE</wrapper.version>here

When I hit the API with the cloud function pointing to echo function, I get a response with the body of the request removed!

I setup below test to debug the issue. Found that the below highlighted code from

org.springframework.cloud.function.adapter.aws.AWSLambdaUtils

is causing the issue. I see that the highlighted line is removed in the 4X branch. Request to kindly guide how to incorporate that fix into my project while staying on the release version of the dependencies.

enter image description here

public static void main(String[] args) {
    String message = "{\r\n"
            + "    \"version\": \"2.0\",\r\n"
            + "    \"routeKey\": \"POST /updatePet\",\r\n"
            + "    \"rawPath\": \"/updatePet\",\r\n"
            + "    \"rawQueryString\": \"\",\r\n"
            + "    \"headers\": {\r\n"
            + "        \"accept\": \"*/*\",\r\n"
            + "        \"accept-encoding\": \"gzip, deflate, br\",\r\n"
            + "        \"content-length\": \"77\",\r\n"
            + "        \"content-type\": \"application/json\",\r\n"
            + "        \"host\": \"XXXXXX.execute-api.ap-south-1.amazonaws.com\",\r\n"
            + "        \"postman-token\": \"2004009f-2661-46ea-9a31-2d6be0bb9281\",\r\n"
            + "        \"user-agent\": \"PostmanRuntime/7.29.0\",\r\n"
            + "        \"x-amzn-trace-id\": \"Root=1-62823410-XXXXXXXXXXXXX\",\r\n"
            + "        \"x-forwarded-for\": \"111.11.111.111, 111.111.111.111\",\r\n"
            + "        \"x-forwarded-port\": \"443\",\r\n"
            + "        \"x-forwarded-proto\": \"https\"\r\n"
            + "    },\r\n"
            + "    \"requestContext\": {\r\n"
            + "        \"accountId\": \"123456733\",\r\n"
            + "        \"apiId\": \"xxxxx\",\r\n"
            + "        \"domainName\": \"xxxxxx.execute-api.ap-south-1.amazonaws.com\",\r\n"
            + "        \"domainPrefix\": \"vaoo36b2l5\",\r\n"
            + "        \"http\": {\r\n"
            + "            \"method\": \"POST\",\r\n"
            + "            \"path\": \"/updatePet\",\r\n"
            + "            \"protocol\": \"HTTP/1.1\",\r\n"
            + "            \"sourceIp\": \"1.1.1.1\",\r\n"
            + "            \"userAgent\": \"PostmanRuntime/7.29.0\"\r\n"
            + "        },\r\n"
            + "        \"requestId\": \"SN0SoioabccwEJuQ=\",\r\n"
            + "        \"routeKey\": \"POST /updatePet\",\r\n"
            + "        \"stage\": \"$default\",\r\n"
            + "        \"time\": \"16/May/2022:11:22:56 +0000\",\r\n"
            + "        \"timeEpoch\": 1652700176657\r\n"
            + "    },\r\n"
            + "    \"body\": \"{\\r\\n\\\"id\\\":1,\\r\\n\\\"name\\\":\\\"toto\\\",\\r\\n\\\"type\\\":\\\"dog\\\",\\r\\n\\\"owner\\\":{\\\"name\\\":\\\"test\\\",\\\"age\\\":8}\\r\\n}\",\r\n"
            + "    \"isBase64Encoded\": false\r\n"
            + "}";
    
    Message<byte[]> msg = AWSLambdaUtils.generateMessage(message.getBytes(StandardCharsets.UTF_8), headers(), String.class, mapper());
    
    var payload = new String(msg.getPayload(),StandardCharsets.UTF_8);
    
    System.out.println("payload is"+payload);
}
Vasco
  • 782
  • 1
  • 5
  • 22
  • I am not sure I follow. The 4.x branch is `main` and that line is still there. I am not saying there is no issue, but can you please describe the behavior you expect? For example, it would be best of you could provide JSON input and JSON output you would expect for such input with some trivial (i.e., uppercase) function in-between (i – Oleg Zhurakousky May 16 '22 at 17:15
  • I was referring to this version: https://github.com/spring-cloud/spring-cloud-function/blob/4.x/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java. – Vasco May 17 '22 at 02:23
  • My test is against a trivial function. echo function which takes the input as String and returns the same String. The expected output is the body of the request ie, {"id":1,"name":"toto","type":"dog","owner":{"name":"dorothy","age":8}} but the response is the API Gateway request payload(pls refer to input message in the test harness) with the body attribute removed. – Vasco May 17 '22 at 02:28
  • Please note that I am running a CustomRuntime in AWS lambda built using native Image. The handler is functionRouter. I have RoutingCallback that looks for a header. The header is inserted in API gateway lambda integration with request mapping. – Vasco May 17 '22 at 02:31
  • The branch you are referencing has long been merged to `main`. It is now a dead branch, I will delete it shortly. Please test agains `main`. – Oleg Zhurakousky May 17 '22 at 10:54
  • I am testing against the binary- 3.2.4. Is there a version that I could use that would resolve the issue? – Vasco May 17 '22 at 11:05

0 Answers0