0
votes

I have been trying to make a getItem request in an async Lambda function to dynamo DB, and I am not receiving any response at all. Any troubleshooting or help would be greatly appreciated.

in general, I am trying to make a request to a dynamodb table using the AWS SDK getItem, however, when I run my code there is no response for the await ddb.getItem function

so I am kinda lost as to what could be causing this.

// 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;


1
That would suggest that the getItem call failed. Did you check the response of the invocation? Perhaps add a console.log in the catch block to log the error. - gideonparanoid

1 Answers

0
votes

You have put the getitem call in try block, as you are not receiving any response means something is gone wrong in the try block.