This is my code:
var ddb = new AWS.DynamoDB();
const tableName = 'Table_One';
let client_id = "a3bdso310";
console.log(`"${client_id}"`);
var params = {
TableName: tableName,
Key: {
'client_id': {S: client_id}
},
};
ddb.getItem(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
let str_client_data = JSON.stringify(data.Item.client_data.S);
let parsed_client_data_str = JSON.parse(str_client_data);
let parsed_data = JSON.parse(parsed_client_data_str)
res.send(parsed_data);
}
});
I am getting an error when I try to perform a GetItem using DynamoDB SDK: "The provided key element does not match the schema". Whenever I replace {S: client_id}
with the actual value like this {S: "a3bdso310"}
it works just find. Can the "Key" value not be a variable? What is even weirder is that when I test this locally it works just fine, the issue is only occurring when I deploy my local project to an EC2. So basically when I run this project on my local machine, everything is the same, the only difference I can think of when running it in an EC2 instance is maybe the fact that the EC2 instance has to have permissions to perform operations on my DynamoDB table. But I already gave it permissions, and other operations work fine that don't require a key (e.g. scan). Is there a solution around this?