Hey there - currently trying to run sst start loca...
# help
c
Hey there - currently trying to run sst start locally. I have set up an Api resource pointing to a lambda, and in that lambda I am trying to use the
pg
npm package to make the connection. I have also tried using
serverless-postgres
with the same results. I am getting an error about not able to resolve pg-native.
Copy code
> node_modules/pg/lib/native/client.js:4:21: error: Could not resolve "pg-native" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
the code implementation looks like:
Copy code
const { Pool } = require('pg')
// import ServerlessClient from 'serverless-postgres'

const pool = new Pool({
  user: process.env.DB_USER,
  host: process.env.DB_HOST,
  database: process.env.DB_NAME,
  password: process.env.DB_PASSWORD,
  port: Number(process.env.DB_PORT),
  debug: true,
  delayMs: 3000,
})
Any help would be greatly appreciated!
Ok I seem to have resolved this (at least locally) after some searching around.
Copy code
const api = new Api(this, 'TriggerVideoMigrationsApi', {
      defaultFunctionProps: {
        bundle: {
          externalModules: ['pg-native'],
        },
      },
      routes: {
        // ...
      },
    })
f
Hey @Cam Sloan, yeah that’s the way to do it! Glad you figured it out.
w
@bike-bill check this out. same problem we're seeing now
f
@William Hatch @bike-bill lemme know if Cam’s solution works for you guys.
w
@Frank yes, that worked for us. Sorry for the delay in responding. We're now onto solving atlas/mongo connection issues, which we feel are more related to lambda and atlas in general.
f
@William Hatch have you checked out their new serverless offering? Here’s an example https://serverless-stack.com/examples/how-to-use-mongodb-atlas-in-your-serverless-app.html
b
That looks good @Frank. Thanks, we'll try it out!
w
revisiting this due to current issues... No, we''re not using the serverless variety of atlas, as it didn't seem appropriate for our use case, after reading 'not meant for higher volume...' So, we're using a standard cluster configuration. We are using that guide for managing connections and caching, however. But, we're having a heck of a time, and it's not at all reliable at the moment.