1
  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

1
  • what is replaceAll ? should it be event.queryStringParameters.authorId.replace(" ", "-").toLowerCase(); Commented Jan 14, 2021 at 3:11

1 Answer 1

2

This is probably because you are using async function handler which finishes before you get any results. One way to overcome this is using a Promise pattern as shown in aws docs.

Or maybe you don't want to use async handler at all. In this case you should remove async from your function and adjust the handler as shown in docs for non-async handlers.

Sign up to request clarification or add additional context in comments.

2 Comments

lol I just removed it and it worked, so I put the async because it makes sense to create the data and then handle whatever else is happening no? and thanks for the docs
@Arturo I don't have particular opinion/insight on that.

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.