Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Can the Key value for DynamoDB be a variable or does it have to be hardcoded?

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!