# API Gateway and Lambda function in java

**URL:** <https://forum.serverless.com/t/api-gateway-and-lambda-function-in-java/1636>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [April 5, 2017, 7:29am UTC](https://forum.serverless.com/t/api-gateway-and-lambda-function-in-java/1636 "2017-04-05T07:29:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdrnaik24](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kdrnaik24](https://forum.serverless.com/u/kdrnaik24)\
**Post date:** [April 5, 2017, 7:29am UTC](https://forum.serverless.com/t/api-gateway-and-lambda-function-in-java/1636/1 "2017-04-05T07:29:28Z")

</div>

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](http://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')"
```

---

<div class="post-metadata">

**Author:** ![bbilger](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bbilger/32/1066_2.png) [@bbilger](https://forum.serverless.com/u/bbilger)\
**Post date:** [April 5, 2017, 7:26pm UTC](https://forum.serverless.com/t/api-gateway-and-lambda-function-in-java/1636/2 "2017-04-05T19:26:05Z")

</div>

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

```java
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](https://github.com/bbilger/jrestless) in case you are interested)

---

<div class="post-metadata">

**Author:** ![kdrnaik24](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kdrnaik24](https://forum.serverless.com/u/kdrnaik24)\
**Post date:** [April 6, 2017, 9:25am UTC](https://forum.serverless.com/t/api-gateway-and-lambda-function-in-java/1636/3 "2017-04-06T09:25:28Z")

</div>

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