title: AWS API Gateway "Unsupported method \"undefined\"" as response
body: <p>I am setting up a AWS Lambda function to connect to my DynamoDB. To access it I'm also setting up an API Gateway.</p>
  
  <p>The lambda seems to work when I test it. Because of this I believe the issue to be in the API gateway setup. </p>
  
  <p><a href="https://i.stack.imgur.com/xvXbZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xvXbZ.png" alt="API Gateway setup"></a></p>
  
  <p>For the lambda I have configured the following test event:
  I have configured a test event which looks like this:</p>
  
  <pre><code>{
    "httpMethod": "GET"
  }
  </code></pre>
  
  <p>This test event gives me the following response:</p>
  
  <pre><code>Response:
  {
    "statusCode": "200",
    "body": "{\"Items\":[{\"id\":1,\"brand\":\"Test brand\",\"title\":\"Test product\"}],\"Count\":1,\"ScannedCount\":1}",
    "headers": {
      "Content-Type": "application/json"
    }
  }
  </code></pre>
  
  <p>For the API Gateway I have tried with the following test:
  <a href="https://i.stack.imgur.com/fCtjq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fCtjq.png" alt="API Gateway test"></a></p>
  
  <p>I have tried automatically creating the API Gateway in the lambda management console. Recreating the lambda and the API Gateway. </p>
  
  <p>Lambda function:</p>
  
  <pre><code>console.log('Loading function');
  
  const doc = require('dynamodb-doc');
  
  const dynamo = new doc.DynamoDB();
  
  
  /**
   * Demonstrates a simple HTTP endpoint using API Gateway. You have full
   * access to the request and response payload, including headers and
   * status code.
   *
   * To scan a DynamoDB table, make a GET request with the TableName as a
   * query string parameter. To put, update, or delete an item, make a POST,
   * PUT, or DELETE request respectively, passing in the payload to the
   * DynamoDB API as a JSON body.
   */
  exports.handler = (event, context, callback) =&gt; {
      //console.log('Received event:', JSON.stringify(event, null, 2));
  
      const done = (err, res) =&gt; callback(null, {
          statusCode: err ? '400' : '200',
          body: err ? err.message : JSON.stringify(res),
          headers: {
              'Content-Type': 'application/json',
          },
      });
  
      switch (event.httpMethod) {
          case 'DELETE':
              dynamo.deleteItem(JSON.parse(event.body), done);
              break;
          case 'GET':
              dynamo.scan({ "TableName": "productdb" }, done);
              //dynamo.scan({"TableName":"productdb"})
              break;
          case 'POST':
              dynamo.putItem(JSON.parse(event.body), done);
              break;
          case 'PUT':
              dynamo.updateItem(JSON.parse(event.body), done);
              break;
          default:
              done(new Error(`Unsupported method "${event.httpMethod}"`));
      }
  };
  
  </code></pre>
  
  <p>API Gateway logs from the test:</p>
  
  <pre><code>Execution log for request 885e5505-2212-11e9-aee0-7f024016f574
  Sun Jan 27 09:04:20 UTC 2019 : Starting execution for request: 885e5505-2212-11e9-aee0-7f024016f574
  Sun Jan 27 09:04:20 UTC 2019 : HTTP Method: GET, Resource Path: /
  Sun Jan 27 09:04:20 UTC 2019 : Method request path: {}
  Sun Jan 27 09:04:20 UTC 2019 : Method request query string: {}
  Sun Jan 27 09:04:20 UTC 2019 : Method request headers: {}
  Sun Jan 27 09:04:20 UTC 2019 : Method request body before transformations: 
  Sun Jan 27 09:04:20 UTC 2019 : Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:304886708348:function:dynamoDBService/invocations
  Sun Jan 27 09:04:20 UTC 2019 : Endpoint request headers: {x-amzn-lambda-integration-tag=885e5505-2212-11e9-aee0-7f024016f574, Authorization=*****************************************************************************************************************************************************************************************************************************************************************************************500617, X-Amz-Date=20190127T090420Z, x-amzn-apigateway-api-id=lqhm3agxxf, X-Amz-Source-Arn=arn:aws:execute-api:eu-central-1:304886708348:lqhm3agxxf/test-invoke-stage/GET/, Accept=application/json, User-Agent=AmazonAPIGateway_lqhm3agxxf, X-Amz-Security-Token=FQoGZXIvYXdzEOH//////////wEaDFvawdYGjH/+gSI14yK9AzQFZtlDghAr2NUHIhLGWmeJkKL8sUP3L6fu0h5PtFPN7wA7hgfWMtUNHCWyGykG0g5Zs81zKx5bUGMLCMK2zuVwD4WMgBRmkx40bZYehHdeS8czOxRTbQIqwP1lfZ0d74l4MqG4g8XpigkcLACLEn6buaq37rO4WYOo+J8ecFeSpti+u+V8OON4idxxXEHiYGJEc23OwjVvf3GTr1EUscB+Lsp/nw58oCWQArUA6LLSwcnGYXYcmnPav2Xs8mJgvqnVowxxYre0N8Gca8D9XBN2Y93/qnVTsOI5nWHSUQOnwaoXSZzgBAXKrUV1S5X+UH3zQI9p [TRUNCATED]
  Sun Jan 27 09:04:20 UTC 2019 : Endpoint request body after transformations: 
  Sun Jan 27 09:04:20 UTC 2019 : Sending request to https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:304886708348:function:dynamoDBService/invocations
  Sun Jan 27 09:04:20 UTC 2019 : Received response. Integration latency: 17 ms
  Sun Jan 27 09:04:20 UTC 2019 : Endpoint response body before transformations: {"statusCode":"400","body":"Unsupported method \"undefined\"","headers":{"Content-Type":"application/json"}}
  Sun Jan 27 09:04:20 UTC 2019 : Endpoint response headers: {Date=Sun, 27 Jan 2019 09:04:20 GMT, Content-Type=application/json, Content-Length=108, Connection=keep-alive, x-amzn-RequestId=6c00229e-caa1-4d37-aeaa-7c1cbd0ddd71, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5c4d7414-e52b0fba267596b50fdbb102;sampled=0}
  Sun Jan 27 09:04:20 UTC 2019 : Method response body after transformations: {"statusCode":"400","body":"Unsupported method \"undefined\"","headers":{"Content-Type":"application/json"}}
  Sun Jan 27 09:04:20 UTC 2019 : Method response headers: {X-Amzn-Trace-Id=Root=1-5c4d7414-e52b0fba267596b50fdbb102;Sampled=0, Access-Control-Allow-Origin=*, Content-Type=application/json}
  Sun Jan 27 09:04:20 UTC 2019 : Successfully completed execution
  Sun Jan 27 09:04:20 UTC 2019 : Method completed with status: 200
  </code></pre>
  
  <p>I expect the result to be the same as the test event in the lambda returns.</p>