title: AWS API Gateway always returns 502 bad gateway
body: <p>I have created a simple lambda function in AWS that returns list from DynamoDB. I have also created API Gateway to trigger the lambda function. The function works fine when I test in AWS console. But I always get 502 bad gateway below error when I test this function in Postman.
   ({
      "message": "Internal server error"
  }</p>
  
  <p>Below is the function in node.js:</p>
  
  <pre><code>const doc = require('dynamodb-doc');
  
  const dynamo = new doc.DynamoDB();
  
  /**
   * Provide an event that contains the following keys:
   *
   *   - operation: one of the operations in the switch statement below
   *   - tableName: required for operations that interact with DynamoDB
   *   - payload: a parameter to pass to the operation being performed
   */
  exports.handler = async (event) =&gt; {
  
      const operation = event.operation;
      const payload = event.payload;
  
      if (event.tableName) {
          payload.TableName = event.tableName;
      }
  
      switch (operation) {
          case 'create':
              return await dynamo.putItem(payload).promise();
          case 'read':
              return await dynamo.getItem(payload).promise();
          case 'update':
              return await dynamo.updateItem(payload).promise();
          case 'delete':
              return await dynamo.deleteItem(payload).promise();
          case 'list':
              return await dynamo.scan(payload).promise();
          case 'echo':
              return payload;
          case 'ping':
              return 'pong';
          default:
              throw new Error(`Unrecognized operation "${operation}"`);
      }
  };
  </code></pre>
  
  <p>Below is generated API Gateway Endpoint details. </p>
  
  <pre><code>API endpoint: https://iabzqisam7.execute-api.us-east-1.amazonaws.com/test/moneyAppDynamoDBOperationsLambda
  Authorization: NONE
  Method: ANY
  Resource path: /moneyAppDynamoDBOperationsLambda
  Stage: test
  </code></pre>
  
  <p>Here is how I am trying to test API using Postman:</p>
  
  <pre><code> Postman  URL(Get) : https://iabzqisam7.execute-api.us-east-1.amazonaws.com/test/moneyAppDynamoDBOperationsLambda
  
      Headers: Key: content-type, Value: application/json
      Body (raw) :
      {
          "operation": "list",
          "tableName": "Advertiser",
          "payload": {
              "TableName": "Advertiser"
          }
      }
  </code></pre>
  
  <p>It works perfectly fine within AWS console.</p>
  
  <p>Any idea why I am keep getting 502 bad gateway error while calling API Gateway from Postman ?</p>