首页 > 解决方案 > DyanmoDB getItem 未在 Async Lambda 中提供任何响应

问题描述

我一直在尝试在异步 Lambda 函数中向 dynamo DB 发出 getItem 请求,但我根本没有收到任何响应。任何故障排除或帮助将不胜感激。

一般来说,我正在尝试使用 AWS SDK getItem 向 dynamodb 表发出请求,但是,当我运行我的代码时,等待 ddb.getItem 函数没有响应

所以我有点不知道是什么原因造成的。

// Load AWS SDK
const AWS = require("aws-sdk");
// Set the region
AWS.config.update({ region: "us-east-1" });

// Create the DyanmoDB service object
const ddb = new AWS.DynamoDB({ apiVersion: "2012-08-10" });

const handler = async (
  event,
  context,
  callback,
  test = false,
  testObjFunc = {
    test: () => {
      Error("Testing enabled");
    }
  }
) => {
  const response = {
    isBase64Encoded: false,
    statusCode: 200,
    headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" },
    multiValueHeaders: {},
    body: JSON.stringify({ responseBody })
  };

  try {
    // Parameters for DynamodDB getItem call
    const dbParams = {
      TableName: "Table_Name",
      Key: {
        personID: { S: "value" }
      },
      ProjectionExpression: "value_to_return"
    };

    // DynamoDB call to check for item
    const results = await ddb.getItem(dbParams).promise();
    console.log("success");
    console.log(results);

  } catch (error) {
    response.statusCode = 500;
  }

  return response;
};
module.exports.handler = handler;


标签: javascriptnode.jsasynchronousaws-lambdaamazon-dynamodb

解决方案


您已将 getitem 调用放入 try 块中,因为您没有收到任何响应意味着 try 块中出现问题。


推荐阅读