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
질문됨 2년 전397회 조회
1개 답변
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
전문가
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠