How to delete OTP in dynamodb after certain mins(2mins)

I have been using setImmediate Timeout function by passing deleteOTP function and userId details of OTP to be deleted in it.I am facing issues with passing the argument(userId) to deleteOTP function in setImmediate.Is there any solution,suggestion are much appreciated.

var update = setImmediate(deleteOTP,10000,userId);

function deleteOTP(Id) {
        var params = {
            Key: {
                "id": {
                   S: Id
            UpdateExpression: "set otp=:x",
            ExpressionAttributeValues: {
                ":x": { S: "null" },
            TableName: tableName

        dynamodb.updateItem(params, function (err, data) {
            if (err){
                console.log(err, err.stack); // an error occurred
                return data

1 answer

  • answered 2019-01-11 05:48 IftekharDani

    You are doing console wrong id.

    user typeof(Id) instead typeof(id)

    below is working code to print id

    var update = setImmediate(deleteOTP,1000,3);
    function deleteOTP(Id) {
      console.log("ID ===>",typeof(Id))
      console.log("ID ===>",Id)