代码之家  ›  专栏  ›  技术社区  ›  yudhiesh

AWS Lambda测试不从DynamoDB表返回数据

  •  1
  • yudhiesh  · 技术社区  · 4 年前

    我试图从我的DynamoDB表dashboard获取数据,所以我用表中的一个示例测试Lambda函数。

    但我从考试中得到的只是:

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

    {
      "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"
    }
    

    "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);
       }
    };
    
    1 回复  |  直到 4 年前
        1
  •  1
  •   Marcin    4 年前

    这个问题是由 未部署 添加新代码后的函数。随后,执行先前部署的版本(即“Hello from Lambda”)。

    这个 是部署新功能。