0

I have tried in many ways. The code works when I test from the AWS console but when I try with Postman it does not run.

exports.main = async function handler(event) {
    event.Records.filter( async (record) => {
        if (record.eventName.toUpperCase() === "INSERT") {
            const recordType = record.dynamodb.NewImage.type.S;

            if (recordType.toUpperCase() === "TASKTYPE") {
                 // here I get the arguments value. Works fine. 

                await submitSearchTask(keyword, key, tag); // it also get called. No problem
            }
        }
    });
};

Submit Search Function

 const submitSearchTask = async function handler(keyword, key, tag) {
    const url = "***"; // the endpoint works fine. 

    const response = await fetch(url, {
        method: "POST",
        headers: getDfsRequestHeader(),// getDfsRequestHeader() also works fine 
        body: JSON.stringify(getPostArray(keyword, tag)),// getPostArray() also works 
    });

    const result = await response.json();
      console.log(result) // it does not work. Nothing showed in the cloudwatch log 

    const taskId = result.tasks[0].id;// locally it works fine
     
    console.log(taskId); // it does not work. Nothing showed in the cloud watch log 
     
     
};

I will highly appreciate any help and guidance.

Ben Jonson
  • 565
  • 7
  • 22
  • This function is being invoked by a DynamoDB Stream, how do you call it via Postman? What URL are you using? – Robert Kossendey Sep 23 '21 at 12:33
  • There is an API endpoint (https://*****.execute-api.us-east-1.amazonaws.com/dev/tasks) that I call from the postman with supplying the input. Once a certain condition is met is entered, then I want to call the external api. – Ben Jonson Sep 23 '21 at 12:40
  • So this Lambda has two triggers, DynamoDB Streams and API Gateway, correct? – Robert Kossendey Sep 23 '21 at 12:40
  • This lambda adds a record to the dynamodb. Another lambda listens to the stream event and then calls the external API if certain conditions are met. Btw I checked if submitSearchTask is called using a console.log, and found it invoked rightly even though fetch not working. – Ben Jonson Sep 23 '21 at 12:49

0 Answers0