Lambda Function dynamodb

0

Hello, I am learning lambda function. I am using nodejs16.x runtime and aws-sdk to perform CRUD operation in dynamodb tables. I am using aws management console to this. I created a table in dynamodb the table has partition key as id then i inserted an item into it that looks like this {"id" : {S : "someid"}, "views" : {N : "0"}} . Now using lambda function I am updating this item's view property; for that I am incrementing the views by 1. after running the function the returned object is correct and show the new values of views for that item as 1. But when I open the dynamodb console and see the table, the views property value is not 1 but 2. And therefore on 2nd execution --> return {views : 3} where as this should be 2 but in dynamodb console the value is now at 4.

lambda function Enter image description here

Dynamodb Table Enter image description here

executing lambda function Enter image description here

dyamodb table item -- now view should be 1 but it shows 2 Enter image description here

  • first decouple the variable like this,

    app.post('/submit', function(req, res) {
    
        // console.log(req.body)
        satelize.satelize({
            ip: req.body.userIp
        }, function(err, payload) {
            // console.log(payload)
            var input = {
                "Created_on": new Date().toString(),
                "Name": req.body.name,
                "Email": req.body.email,
                "Company": req.body.company,
                "Subject": req.body.subject,
                "Message": req.body.message,
                "UserInfo": JSON.stringify(payload)
            };
    
            var params = {
                TableName: Leads_table_name,
                Item: input
            };
    
            docClient.put(params, function(err, data) {
    
                if (err) {
                    console.log("users::save::error - " + JSON.stringify(err, null, 2));
                } else {
                    console.log("users::save::success");
                }
            });
        })
        res.sendFile('public/response.html', {
            root: __dirname
        })
    
subham
demandé il y a 2 ans397 vues
1 réponse
0

I was able to reproduce your issue. Will need to do more research and ask some Node.js experts, as I am primarily from a Java background. However, following all documentation and code samples on even third-party sites like Stackoverflow, what you are doing in your code seemed to be in line. I even tried using ADD instead of SET, but the value in DynamoDb was always incrementing by 2.

profile pictureAWS
EXPERT
répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions