Answers: <p>I've resolved the issue now. </p>
  
  <p>First of all, console.log(e) should be used to log the result. Then the error will appear in CloudWatch. </p>
  
  <p>The problem was that the role that was used by the lambda did not permit invoking other lambdas. This can be fixed by granting the missing InvokeFunction permission for the role.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-22T08:58:10.193Z
Answers: 2019-04-22T08:58:10.193Z
Answers: romanbird
Answers: <p>Generally speaking a good practice for AWS Lambda is to map what are the services and permissions required for it to run properly then create a dedicated role for it with the required policies. I also recommend not using roles on multiple Lambdas, it tends to get very insecure fast if you do.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-23T22:42:53.430Z
Answers: 2019-04-23T22:42:53.430Z
Answers: GelosSnake
Body: <p>I have a node.js lambda function that adds a database entry and then calls another lambda function. The code works fine when I test locally via</p>
  
  <pre><code>serverless invoke local --function create --path mocks/create-event.json
  </code></pre>
  
  <p>but it fails when I invoke the deployment</p>
  
  <pre><code>aws lambda invoke  --function-name create --payload file://mocks/create-event.json out.txt
  </code></pre>
  
  <p>here is the relevant lambda code:</p>
  
  <pre><code>try {
      await dynamoDbLib.call("put", params);  //OK locally and in deployment
      var lambda = new AWS.Lambda();
      const req = {
        FunctionName: 'eqtor-api-dev-mysim', 
        InvocationType: 'RequestResponse',
        LogType: 'Tail',
        Payload: JSON.stringify({ name: 'me' })
      };
      const result = await lambda.invoke(req).promise(); //OK locally but not in deployment
      console.log(result); 
      return success(params.Item);
    } catch (e) {
      return failure({ status: false });
    }
  </code></pre>
  
  <p>The command shows </p>
  
  <pre><code>{
      "ExecutedVersion": "$LATEST", 
      "StatusCode": 200
  }
  </code></pre>
  
  <p>and in out.txt, I get </p>
  
  <pre><code>{"statusCode":500,"headers":{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":true},"body":"{\"status\":false}"}
  </code></pre>
  
  <p>Any tips on how to debug this?</p>
  
Tags: <aws-lambda><node.js>
Title: AWS lambda: works locally but fails in deplyment
UserDisplayName: romanbird
ThreadText: # AWS lambda: works locally but fails in deplyment
  
  (Asked by: username_0 on 2019-04-22)
  
  I have a node.js lambda function that adds a database entry and then calls another lambda function. The code works fine when I test locally via
  
  ```
  serverless invoke local --function create --path mocks/create-event.json
  
  ```
  
  but it fails when I invoke the deployment
  
  ```
  aws lambda invoke  --function-name create --payload file://mocks/create-event.json out.txt
  
  ```
  
  here is the relevant lambda code:
  
  ```
  try {
      await dynamoDbLib.call("put", params);  //OK locally and in deployment
      var lambda = new AWS.Lambda();
      const req = {
        FunctionName: 'eqtor-api-dev-mysim', 
        InvocationType: 'RequestResponse',
        LogType: 'Tail',
        Payload: JSON.stringify({ name: 'me' })
      };
      const result = await lambda.invoke(req).promise(); //OK locally but not in deployment
      console.log(result); 
      return success(params.Item);
    } catch (e) {
      return failure({ status: false });
    }
  
  ```
  
  The command shows
  
  ```
  {
      "ExecutedVersion": "$LATEST", 
      "StatusCode": 200
  }
  
  ```
  
  and in out.txt, I get
  
  ```
  {"statusCode":500,"headers":{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":true},"body":"{\"status\":false}"}
  
  ```
  
  Any tips on how to debug this?
  
  **Tags:** aws-lambda, node.js
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2019-04-22. Score: 1
  
  I've resolved the issue now.
  
  First of all, console.log(e) should be used to log the result. Then the error will appear in CloudWatch.
  
  The problem was that the role that was used by the lambda did not permit invoking other lambdas. This can be fixed by granting the missing InvokeFunction permission for the role.
  
  
  ---
  
  ### Answer by username_1 on 2019-04-23. Score: 0
  
  Generally speaking a good practice for AWS Lambda is to map what are the services and permissions required for it to run properly then create a dedicated role for it with the required policies. I also recommend not using roles on multiple Lambdas, it tends to get very insecure fast if you do.
  
  
  ---
  
  