I have a Node.js Lambda function that uses AWS DocumentClient to find an item by primary key in a DynamoDB table. This worked fine in AWS SDK v2 and returned the item data. The item does exist in the database.
var params = {
TableName : TBL_ICT_DEVICES,
Key: {
'imei': imei
}
};
_docClient.get(params,function(err,data){
...
When I switched to AWS SDK using GetCommand the item is not found
Here is the v3 code I use
const getCommand = new GetCommand({
TableName: TBL_ICT_DEVICES,
Key: {
imei: imei
},
ConsistentRead: true,
});
console.log("command = " + JSON.stringify(getCommand));
const getResponse = await _docClient.send(getCommand);
Here are the relevant lines from the execution log
2023-08-17T14:10:19.908Z 613a7a50-3c3e-4eee-8f76-5614b97d1631 INFO command = {"middlewareStack":{},"input":{"TableName":"ict_devices","Key":{"imei":"865284042591606"},"ConsistentRead":true},"inputKeyNodes":[{"key":"Key"}],"outputKeyNodes":[{"key":"Item"}],"clientCommand":{"middlewareStack":{},"input":{"TableName":"ict_devices","Key":{"imei":"865284042591606"},"ConsistentRead":true}}}
2023-08-17T14:10:20.155Z 613a7a50-3c3e-4eee-8f76-5614b97d1631 INFO Query error : {"name":"ResourceNotFoundException","$fault":"client","$metadata":{"httpStatusCode":400,"requestId":"QBA35I5NBBHMOS3IVNGQIGQ01BVV4KQNSO5AEMVJF66Q9ASUAAJG","attempts":1,"totalRetryDelay":0},"__type":"com.amazonaws.dynamodb.v20120810#ResourceNotFoundException"}
What am I missing?
Thank you
Andy
Adding type information did not work
Tried both DynamoDB and DocumentClient
The client objects are declared as follows
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, GetCommand,PutCommand } from "@aws-sdk/lib-dynamodb";
const _ddbClient = new DynamoDBClient({});
const _docClient = DynamoDBDocumentClient.from(_ddbClient);