Trying to run a BatchGetItem from Lambda to DynamoDB however When I run the query it returns a null response and logs no issues. PK (Primary Key) and SK (Sort Key) do exist in the table and the values associated with each are currently stored in the table as seen below. The Lambda function has permissions to run BatchGetItem on that specific table and when I run a single GetItem on that same table it works fine and returns a single item. Any help with trying to get BatchGetItem to return the queried items would be greatly appreciated. Thanks
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'us-east-1'});
// Create DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var info;
exports.handler = async (event, context) => {
var params = {
RequestItems: {
"candidates": {
Keys: [
{
"PK": {S: "jack"},
"SK": {S: "C108951642"}
},
{
"PK": {S: "ben"},
"SK": {S: "C143956179"}
},
{
"PK": {S: "hill"},
"SK": {S: "C268283233"}
}
],
ProjectionExpression: "Name"
}
}
};
ddb.batchGetItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
data.Responses.TABLE_NAME.forEach(function(element, index, array) {
console.log(element);
info = element;
});
}
});
return info;
}
Test Event Name
batch
Response
null
Function Logs
START RequestId: a411114a-29b9-4f7f-bc20-2a5caff9f0cf Version: $LATEST
END RequestId: a411114a-29b9-4f7f-bc20-2a5caff9f0cf
REPORT RequestId: a411114a-29b9-4f7f-bc20-2a5caff9f0cf Duration: 442.11 ms Billed Duration: 443 ms Memory Size: 128 MB Max Memory Used: 78 MB
Request ID
a411114a-29b9-4f7f-bc20-2a5caff9f0cf