Lambda doesn’t create data in DynamoDB

  1. I get a code response 200 successful

  2. but a null json message on Postman

  3. Data is not created in DynamoDB. This is my lambda:

    exports.handler = async (event, context, callback) => {
    
     const id = replaceAll(event.queryStringParameters.authorId, " ", "-").toLowerCase();
    
     const params = {
         Item: {
             id: {
                 S: id
             },
             title: {
                 S: event.queryStringParameters.title
             },
             watchHref: {
                 S: event.queryStringParameters.watchHref
             },
             authorId: {
                 S: event.queryStringParameters.authorId
             },
             length: {
                 S: event.queryStringParameters.length
             },
             category: {
                 S: event.queryStringParameters.category
             }
         },
         TableName: "todos"
     };
    
     // console.log("@@@@@@@@@@@ ID " + params.Item.id.S + "");
     // console.log("@@@@@@@@@@@ Title " + params.Item.title.S + "");
     // console.log("@@@@@@@@@@@ Title " + params.Item.watchHref.S + "");
     // console.log("@@@@@@@@@@@ Title " + params.Item.authorId.S + "");
     // console.log("@@@@@@@@@@@ Title " + params.Item.length.S + "");
     // console.log("@@@@@@@@@@@ Title " + params.Item.category.S + "");
    
    
     dynamodb.putItem(params, function (err, data) {
    
         console.log("@@@@@@@@@@@ ID " + params.Item.id.S + "");
    
         if (err) {
             console.log("@@@@@@@@@@@ ERROR" + err);
             callback(err);
         } else {
             console.log("@@@@@@@@@@ INSIDE ELSE");
             callback(null, {
                 id: params.Item.id.S,
                 title: params.Item.title.S,
                 watchHref: params.Item.watchHref.S,
                 authorId: params.Item.authorId.S,
                 length: params.Item.length.S,
                 category: params.Item.category.S
             });
         }
     });
    };
    

What am I doing wrong? I folowed the same principles that on the documentation.

As a reference, I'm doing it with HTTP API gateway proxy integration and this is my table:

enter image description here



Read more here: https://stackoverflow.com/questions/65712784/lambda-doesnt-create-data-in-dynamodb

Content Attribution

This content was originally published by Arturo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: