3 hours ago
Please ensure that your database server is running at `localhost`:`5432` before using SAM CLI.
sam local start-api --profile my-aws-profile --skip-pull-image -p 4000 -t template.yaml -n local.env.json
--docker-networkflag with a setting of "host" to start the SAM local API, and to update the connection string host to be
sam local start-api --profile my-aws-profile --skip-pull-image --docker-network host -p 4000 -t template.yaml -n local.env.json
3 hours ago
It's possible that the issue is related to the way the Postgres container is set up. One thing you could try is to make sure that the container is listening on all interfaces, not just on localhost. Sometimes, the default Postgres configuration will only listen on localhost, which can cause issues when trying to access it from another container. To do this, you can modify the postgresql.conf file inside the Postgres container to include the following line:
Once you've made this change, you'll need to restart the Postgres container to pick up the new configuration. Assuming that you've made this change and restarted the container, you should be able to connect to it from your Lambda function using the same connection string that you posted:
If you're still having issues connecting to the database after making this change, it might be worth looking at the logs for the Postgres container to see if there are any errors being reported there. You might also want to try connecting to the container from outside of the SAM API using a tool like psql to make sure that the container is listening on the right interface and port.