# Newbie : Lambda function – GET doesn't return anything

**URL:** <https://forum.serverless.com/t/newbie-lambda-function-get-doesnt-return-anything/9244>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, dynamodb\
**Created:** [September 7, 2019, 5:29pm UTC](https://forum.serverless.com/t/newbie-lambda-function-get-doesnt-return-anything/9244 "2019-09-07T17:29:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bexeco](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@bexeco](https://forum.serverless.com/u/bexeco)\
**Post date:** [September 7, 2019, 5:29pm UTC](https://forum.serverless.com/t/newbie-lambda-function-get-doesnt-return-anything/9244/1 "2019-09-07T17:29:48Z")

</div>

I am completely new to The Serverless Framework and AWS lambda.

When making a GET request to [http://localhost:3000/user/1e89a3f0-d170-11e9-94bd-91e9ae84f3e9](http://localhost:3000/user/1e89a3f0-d170-11e9-94bd-91e9ae84f3e9) I would expect a response being send back to the browser with a valid JSON object matching the Key. Like the only getting logged out to the console. And not empty document.

Am I returning incorrectly? I am having difficulties debugging this, I don’t now if the problem is with my lambda function, or what it is.

Thank you.

**`console.log` statement**

```auto
{
  email: 'i@am.com',
  password: '$argon2i$v=19$m=4096,t=3,p=1$IIICgcMqbUA7wFpEMqb/GA$ENScjko+Y8pruQsTiE6qN81QAJfAPX/T116RQZqe347Y1p0rez4KhKaEulMeabKKiu8',
  id: '1e89a3f0-d170-11e9-94bd-91e9ae84f3e9'
}

```

Here is the get handler in question.

**users/get.js**

```auto
const AWS = require("aws-sdk");

const dynamoDb = new AWS.DynamoDB.DocumentClient({
  region: "localhost",
  endpoint: "http://localhost:8000"
});

module.exports.get = async event => {
  const params = {
    TableName: process.env.DYNAMODB_TABLE,
    Key: {
      id: event.pathParameters.id
    }
  };

  dynamoDb.get(params, (error, result) => {
    if (error) {
      console.error(error);
      return;
    }
    console.log(result.Item); // logs successfully to the console.
    return {
      // doesn't return a response.
      statusCode: 200,
      body: JSON.stringify(result.Item)
    };
  });
};

```

**serverless.yml**

```auto
# EXCERPT

functions:
  get:
    handler: users/get.get
    events:
      - http:
          method: get
          path: user/{id}
          cors: true

resources:
  Resources:
    UsersDynamoDbTable:
      Type: "AWS::DynamoDB::Table"
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.DYNAMODB_TABLE}

custom:
  dynamodb:
    stages:
      - dev
    start:
      port: 8000
      inMemory: true
      sharedDb: true
      noStart: true

```

---

<div class="post-metadata">

**Author:** ![gap](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@gap](https://forum.serverless.com/u/gap)\
**Post date:** [September 7, 2019, 6:02pm UTC](https://forum.serverless.com/t/newbie-lambda-function-get-doesnt-return-anything/9244/2 "2019-09-07T18:02:42Z")

</div>

The problem is you have declared get as async, but are using callbacks. When you use async, serverless will serve up what you return from this function, which is nothing. There are two solutions:

1. Use callbacks and remove async/await
2. Use async/await and remove the callbacks

To use callbacks remove your async

```auto
module.exports.get = event => { ... }

```

Using async/await requires more changes, but is cleaner code. It would something like:

```auto
module.exports.get = async event => {
  const params = {
    TableName: process.env.DYNAMODB_TABLE,
    Key: {
      id: event.pathParameters.id
    }
  };

  let result = await dynamoDb.get(params);
  console.log(result.Item); // logs successfully to the console.
   return {
      // doesn't return a response.
      statusCode: 200,
      body: JSON.stringify(result.Item)
    };
  });
};

```

I do not use Dynamo and am assuming it returns a promise

Gary

---

<div class="post-metadata">

**Author:** ![bexeco](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@bexeco](https://forum.serverless.com/u/bexeco)\
**Post date:** [September 7, 2019, 6:24pm UTC](https://forum.serverless.com/t/newbie-lambda-function-get-doesnt-return-anything/9244/3 "2019-09-07T18:24:15Z")

</div>

thank you very much Gary for spending the time answering me. I will see if I can make it work with your suggestions in mind.

---

<div class="post-metadata">

**Author:** ![gap](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@gap](https://forum.serverless.com/u/gap)\
**Post date:** [September 7, 2019, 6:36pm UTC](https://forum.serverless.com/t/newbie-lambda-function-get-doesnt-return-anything/9244/4 "2019-09-07T18:36:24Z")

</div>

Your are welcome and good luck!

Gary
