What on earth am I supposed to use as a connection string for lambda -> RDS?

I don’t want to have to sanitize and slim down my large config so instead I ask: what am I supposed to use as a connection string?

My configuration works fine when deployed on AWS and fails on Localstack with ECONNREFUSED 127.0.0.1:4510

The database is running on localhost:4510. Pgadmin connects as expected with exactly the same credentials. My VPC and security groups and what not are correct as it deploys properly on AWS.

I’m running this via the cli with localstack start, run my configs and then create a function URL and then visit that URL which fails.

Am I missing some obvious configuration steps here? Is this not supposed to just work?

Hello @bluewave41,

This fails because your lambda is executed inside a Docker container, and localhost will resolve to the lambda container and not your host or LocalStack.

In order to access LocalStack from inside your lambda, you can use this environment variable set inside your Lambda: LOCALSTACK_HOSTNAME as the host in your connection string, which will resolve to LocalStack and where your Postgres RDS is running.

Here’s the relevant part in the documentation: Configuration | Docs

Hope this helps, don’t hesitate if this doesn’t work.

1 Like