Mongodb connection - An error occurred during deployment of dbProxy

When trying to deploy api I have an error:

An error occurred during deployment of dbProxy
Error: Could not connect to the MongoDB server, make sure the connection string is correct and that the database server allows outside connections. Check https://docs.webiny.com/docs/get-started/quick-start#3-setup-database-connection for more information.
at DbProxyComponent.default (/home/ec2-user/webiny/first-aws-project/node_modules/@webiny/serverless-db-proxy/serverless.js:22:23)

I have installed mongo 3.6, because 4.* cannot be installed with glibc 2.17, and amazon linux doesn’t have 2.18 yet.

So I created a database and user:

use webiny-first
db.createUser(
    {
        user: "webiny-first",
        pwd: "1st_Project_With_Webiny",
        roles: [ { role: "readWrite", db: "webiny-first" },
                { role: "read", db: "config" } ]
    }
)

I tried to connect with the client:

mongo --port 27017 -u "webiny-first" -p "1st_Project_With_Webiny" --authenticationDatabase "webiny-first"

and it worked well.

I have tried different options in .env.json

mongodb+srv://webiny-first:[email protected]
mongodb://webiny-first:[email protected]
mongodb+srv://webiny-first:[email protected]
mongodb://webiny-first:[email protected]

Did not work at all.

Can you help me?

Not really sure about your setup, but your database must be accessible from the internet (anywhere). Since DB connection is created from a Lambda function, it must be able to connect to it from any IP address, so you should whitelist all connections, e.g. 0.0.0.0/0.

If you tell me a little bit more about your setup I’ll be able to provide more information. Maybe you’ve already seen it, but if not, check out this section in our docs about DB connection: https://docs.webiny.com/docs/get-started/quick-start/#3-setup-database-connection

We recommend to use Mongo Atlas, it has free tier, and is more than enough for development purposes. If you really want to host your own DB instance, make sure you can connect to it from anywhere, not just your local computer.

@glodov It seems there is something wrong with accessing your database, either user credentials or a firewall.

In general, since Webiny deploys the services to AWS cloud. Those services must be able to connect to the database via a public IP. Running mongodb locally won’t work here as your IP and port are probably not accessible from a Lambda function. This applies even to your local development environment (link). We recommend you use MongoDB Atlas Free Tier for that. You can find the guide how to set it up here - https://docs.webiny.com/docs/other/guides/mongodb-atlas