title: AWS Lambda in NodeJS error: "Wrong arguments"
body: <p><strong>Scenario</strong></p>
  
  <ul>
  <li>My React (Gatsby) application requests information from a database to display a list of products.</li>
  <li>The database is a Postgres table on AWS RDS, in a VPC.</li>
  <li>My aim is for the React application to trigger an AWS Lambda function to retrieve products from AWS RDS.</li>
  </ul>
  
  <p>Error:</p>
  
  <ul>
  <li>In writing my lambda function, I intend to request all products from my table.</li>
  <li>The error message I get is <code>TypeError: Wrong arguments</code></li>
  </ul>
  
  <p>Code:</p>
  
  <p><strong>index.js</strong></p>
  
  <pre><code>const rds = require('./connection.js');
  
  exports.handler = async ( event, context, callback ) =&gt; {
      await callback(null, rds.getProducts);
  };
  </code></pre>
  
  <p><strong>connection.js</strong></p>
  
  <pre><code>const Pool = require('pg').Pool;
  
  const pool = new Pool({
      user: process.env.user,
      host: process.env.host,
      database: process.env.database,
      password: process.env.password,
      port: process.env.port,
  });
  
  const getProducts = ( request, response ) =&gt; {
      pool.query(`SELECT * FROM product_list ORDER by id ASC`, ( error, result ) =&gt; {
          if( error ) throw new Error(error);
          response.status(200).json(result.rows);
      })
  };
  
  module.exports = {
      getProducts,
  };
  
  </code></pre>
  
  <p><strong>package.json</strong></p>
  
  <pre><code>{
    "name": "lambda3",
    "version": "1.0.0",
    "description": "lambda function access rds",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
    },
    "author": "scott",
    "license": "ISC",
    "dependencies": {
      "pg": "^7.14.0"
    }
  }
  
  </code></pre>
  
  <p>Full error:</p>
  
  <pre><code>{
    "errorType": "TypeError",
    "errorMessage": "Wrong arguments",
    "trace": [
      "TypeError: Wrong arguments",
      "    at RAPIDClient.postInvocationResponse (/var/runtime/RAPIDClient.js:41:18)",
      "    at complete (/var/runtime/CallbackContext.js:34:12)",
      "    at callback (/var/runtime/CallbackContext.js:44:7)",
      "    at /var/runtime/CallbackContext.js:105:16",
      "    at Runtime.exports.handler (/var/task/index.js:9:11)",
      "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
  }
  </code></pre>
  
  <p><strong>Thoughts</strong>: I followed the AWS guide on how to upload a NodeJS deployment package. There didn't seem to be an issue with <code>connection.js</code> when testing locally.</p>
  
  <p>Unsure how to debug this as even "AWS Lambda wrong arguments" yields few relevant results.</p>