0
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'ap-south-1', apiVersion: '2012-08-10'});
exports.handler = (event, context, callback) => { 

updateExpression = null;

var expressionAttributeValues = {};
if (event.father_status != undefined) { 

if (updateExpression == null) {
    updateExpression = "set father_status = :fs";
}

else {
   updateExpression += ", father_status = :fs"
     }

expressionAttributeValues.fs = {S: event.father_status};
   }

   if (event.mother_status != undefined){

if (updateExpression == null) {

updateExpression = "set mother_status = :ms";

}else {
           updateExpression += ", mother_status = :ms"
       } 
     expressionAttributeValues.ms = {S: event.mother_status};
   }

   var params = {
    TableName: "user-family-background",
    Key:{
        "user_id": {
            S: event.user_id
        }
    },
    UpdateExpression: updateExpression,
    ExpressionAttributeValues: expressionAttributeValues,
    ReturnValues:"ALL_NEW"
};

dynamodb.updateItem(params, function(err, data) {
       if(err){
           console.log("error: " + err);
           callback(err);
       }
       else {
           console.log("sucsess: " + JSON.stringify(data));
           callback(null, data);
       }
   });

   console.log(params);
   console.log(updateExpression);
   console.log(JSON.stringify(expressionAttributeValues));

};

I want to create JSON for "expressionAttributeValeus" that is something like this:

{ ':fs': { S: 'employed' }, ':ms': { S: 'homemaker' } }

but I m getting JSON like this

{ 'fs': { S: 'employed' }, 'ms': { S: 'homemaker' } }

without (: colon in front of "fs", and "ms")

If anyone can help that will be appreciated.

1 Answer 1

1

Change your code to

  expressionAttributeValues[':fs'] = {S: event.father_status};

and

  expressionAttributeValues[':ms'] = {S: event.mother_status};
Sign up to request clarification or add additional context in comments.

1 Comment

hey thanks #cementblocks, you solved my problem. very thankful to you.

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.