1

I am trying to get data from my DynamoDB table called dashboard so I am testing out the Lambda function with a sample from the table.

But all I am getting back from the test is :

Response:
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

It should just return the data from the table that matches it based on the ID as that is what I use to partition the table.

Dashboard example data which is also the test I made

{
  "batteryLevel": 35,
  "deviceId": "yxftd9pnitd-156xhref9g69a",
  "eventId": "c07e3f9f-f6bb-4792-be6f-a9be95cdff38",
  "id": 12345,
  "location": {
    "accuracy": 35.369,
    "latitude": 55.8256671,
    "longitude": 37.5962931
  },
  "tags": [
    {
      "accelX": 0.012,
      "accelY": -0.004,
      "accelZ": 1.008,
      "createDate": "2020-08-11T18:51:58+0300",
      "dataFormat": 5,
      "defaultBackground": 2,
      "favorite": true,
      "humidity": 32.8425,
      "id": "E5:F1:98:34:C0:0F",
      "measurementSequenceNumber": 62865,
      "movementCounter": 21,
      "name": "Kitchen",
      "pressure": 98702,
      "rssi": -43,
      "temperature": 25.58,
      "txPower": 4,
      "updateAt": "2020-08-18T19:57:48+0300",
      "voltage": 3.013
    }
  ],
  "time": "2020-08-18T19:57:48+0300"
}

Lambda Function

"use strict";

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

AWS.config.update({ region: "ap-southeast-1" });

exports.handler = async (event, context) => {
    const ddb = new AWS.DynamoDB({ apiVersion: "2012-10-08" });
    const documentClient = new AWS.DynamoDB.DocumentClient({ region: "ap-southeast-1"});
    
    const params = {
        TableName: "dashboard",
        Key: {
            id: 12345
        }
    };
    try {
        const data = await documentClient.get(params);
        console.log(data);
    } catch (err) {
        console.log(err);
   }
};
5
  • Seems like you are executing either wrong function or wrong version of it. Commented Oct 17, 2020 at 6:12
  • I just checked and its using the latest version. Commented Oct 17, 2020 at 6:16
  • 2
    You are outputting Hello from Lambda. This is not coming from the function you've posted. Maybe you did not deploy the function? Commented Oct 17, 2020 at 6:18
  • 1
    Wow yeah that fixed can't believe I forgot to deploy it. Commented Oct 17, 2020 at 6:20
  • 1
    Glad to hear it worked. If you don't mind I will provide an answer for future reference. Commented Oct 17, 2020 at 6:21

1 Answer 1

2

Based on the comments.

The issue was caused by not deploying the function after adding new code. Subsequently, the previously deployed version (i.e. "Hello from Lambda") was being executed.

The solution was to deploy the new function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.