5

I have a dynamo DB query like this. Which I execute to add data to two different table and this question is the continuation of the first question. Using batchWriteItem in dynamodb

  var createuser = {
        "RequestItems": {
          "users": [
            {
              "PutRequest": {
                Item: {
                  "userid": { "N": "usrid" },
                  "role": { "S": 'candidate' },
                  "password": { "S": vucrypt.encryptpass(pass) }
                }
              }
            }
          ],
          "candidate": [
            {
              "PutRequest": {
                Item: {
                  "fname": {
                    "S": req.body.fname
                  },
                  "lname": {
                    "S": req.body.lname
                  },
                  "location": {
                    "S": req.body.location
                  },
                  "phone": {
                    "S": req.body.phone
                  },
                  "ccode": {
                    "S": req.body.ccode
                  },
                  "grad": {
                    "S": req.body.grad
                  },
                  "pgrad": {
                    "S": req.body.pgrad
                  },
                  "ograd": {
                    "S": req.body.ograd
                  },
                  "experience": {
                    "N": "10"
                  },
                  "linkedin": {
                    "S": req.body.linkedin
                  },
                  "terms": {
                    "S": tandc
                  }
                }
              }
            }
          ]
        }
      }

When i excicute this code i am getting an error like this.

ValidationException: A value provided cannot be converted into a number

I tried with this.

var exps = Number(exp);

But still, this error persist what can I do? any idea?

My code is like this.

  dynamodb.batchWriteItem(createuser, function(err, regdata) {
    vulog.debug(regdata);
    if (err || !regdata || regdata.Responses.UnprocessedItems) {
      vulog.warn('ddb: error in checking corp user details1 \n' + err);
      res.send(400, 'Unable to register at present, please try later');
      return;
    }
    vulog.debug('Candidate added successful');

    res.send(200, 'Success! Your account has been created.\n Check your email for further instructions.');
  });

1 Answer 1

1

All the values must be strings:

for example :

"fname": {
    "S": req.body.fname
}

req.body.fname must be a string

so just add

req.body.fname + ""

OR

req.body.fname.toString();

Sign up to request clarification or add additional context in comments.

16 Comments

THis is not working i am keep getting this error ValidationException: A value provided cannot be converted into a number
your error is here "userid": { "N": "usrid" } , delete the quotes from the userid. and cast the userid to string : "userid": { "N": usrid + "" }
still no hope :(
But the error is changed ValidationException: One or more parameter values were invalid: An AttributeValue may not contain an empty string
ok, so according to the error, check if you don't have any empty string, can you do console.log(createuser) and show the result
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.