API Gateway and Lambda function in java

I am trying to deploy lambda function which is written in JAVA and API Gateway using Serverless framework. After deploying my service(lambda function) using node CLI, when I test API, it shows “no data” in response body. It is not showing expected output in API Gateway.
Even when I test lambda function, it shows expected output.My Lambda function is taking key,value (String,Integer) pair as input and returning integer as output.

This is serverless.yml:

service: newService

provider:
name: aws
runtime: java8

stage: QA
region: us-east-1

package:
artifact: target/hello-dev.jar

functions:
hello:
handler: com.serverless.Handler

events:
  - http: 
      path: service
      method: post
      integration: lambda
      response:
       headers: 
       	Content-Type: "'application/json'"
       	template: "$input.path('$.body')"

Hi @kdrnaik24,
Is there any particular reason you are not using “lambda proxy” integration? If not, then you should :wink:
Edit: I read over that you return an integer. That is probably not possible. Can you try returning a object instead:

public class Response {
  private final int value;
  public Response(int value) {
    this.value = value;
  }
  public int getValue() {
    return value;
  }
}

Also your custom response template looks strange to me (but it’s been a while I’ve been using non-proxy integration)

  1. Shouldn’t it just be: template: $input.path('$')
  2. Shouldn’t template be on the same level as headers?

(+ since you are using Java, some promo for my Java framework JRestless in case you are interested)

Hi @bbilger ,Thak you for reply. It’s working now. :slight_smile: