title: how to use node pg in AWS Lambda?
body: <p><strong>UPDATE/SOLVED</strong> ... the problem was that pgpass plugin was looking for $HOME/.pgpass, and $HOME wasn't defined on lambda, causing failure of <code>join(undefined, '.pgpass')</code>. Not really worth crediting myself with an answer for that ....</p>
  
  <p>I have the following test code in a lambda handler (compiled from typescript):</p>
  
  <pre><code>const db = new Pool()
  const {rows} = await db.query('select 1 as x')
  console.log('rows', JSON.stringify(rows))
  </code></pre>
  
  <p>The connection is created via PGHOST PGPORT PGUSER PGDATABASE in the environment. I know the configuration is "almost right" because the first time I tried it I got:</p>
  
  <blockquote>
    <p>{"errorMessage":"error: no pg_hba.conf entry for host \"10.1.1.249\",
    user \"foo\", database \"bar\", SSL off\n    at
    Connection.parseE (/var/task/handler.js:9209:11)\n    at
    Connection.parseMessage (/var/task/handler.js:9034:19)\n    at
    Socket. (/var/task/handler.js:8777:22)\n    at emitOne
    (events.js:96:13)\n    at Socket.emit (events.js:188:7)\n    at
    readableAddChunk (_stream_readable.js:176:18)\n    at
    Socket.Readable.push (_stream_readable.js:134:10)\n    at TCP.onread
    (net.js:547:20)"}</p>
  </blockquote>
  
  <p>That seemed hopeful. I changed the postgres config to allow from the subnet, and tried again. However, now I get:</p>
  
  <pre><code>2018-02-06 18:14:21.183 (-05:00)    76761ca5-0b93-11e8-8783-a74d098c9f4a    select
  2018-02-06 18:14:21.202 (-05:00)    76761ca5-0b93-11e8-8783-a74d098c9f4a    TypeError: Path must be a string. Received undefined
      at assertPath (path.js:7:11)
      at Object.join (path.js:1211:7)
      at Object.module.exports.getFileName (/var/task/handler.js:32434:16)
      at module.exports (/var/task/handler.js:32355:23)
      at Connection.&lt;anonymous&gt; (/var/task/handler.js:31255:9)
      at emitOne (events.js:96:13)
      at Connection.emit (events.js:188:7)
      at Socket.&lt;anonymous&gt; (/var/task/handler.js:8781:12)
      at emitOne (events.js:96:13)
      at Socket.emit (events.js:188:7)
  END RequestId: 76761ca5-0b93-11e8-8783-a74d098c9f4a
  </code></pre>
  
  <p>What is going on? It seemed as if it had got to the database and connected the first time... Now it fails on the <code>query</code>. Is there some option I should be using?</p>