0

I tried to write lambdaa function with node.js and run it on my local with sam-cli but inside that lambda function I have to send some log to the log server with post request but for sending request I tried to use request and axios but none of them didn't make any api call. So what should I do ?

More information:

I have written a lambda function with node.js which should send some log data to the log server inside lambda function but I can not send any data to the log server. So I though maybe log server has error so I tried to send that data with postman and then I was able to send data. I also tried to make request on jsonplaceholder but I also was not able to make any api call like get and send with sam. By the way I used request for it but I also used axios for make some api call but still I could not. So for now I can not any make any request to anywhere I tried to debug it but breakpoint also didn't help me.

By the way there is no any error with another piece of code I only can not send or get any data with using npm request package. when working with sam on my local by the way I was able to make request without sam with npm request package

My lambda Template

Resources:
  sendSomething:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.sendSomething
      Runtime: nodejs8.10
      Environment:
      Timeout: 500
      Events:
        Api:
          Type: Api
          Properties:
            Path: /sendSomething
            Method: post

The code which does not work

There is no any error for loggerUrl and requestBody I only can not send data with working sam-cli

At last I run code with that command sam local start-api

request(
  {
    method: "POST",
    url: loggerUrl,
    body: JSON.stringify(requestBody),
    json: true
  },
  (err, response, body) => {
     console.log("Response body ",body);
    if (err) {
      console.log("Error log: ", err);
    }
  }
);

when code reach request for making post request passed callback function so that any console log does not write both are them console.log("Response body ",body); and console.log("Error log: ", err);

0 Answers0