Using Connection Strings to Connect to Cloud Services

Adrienne Domingus
2 min readJul 29, 2020

Unless a website is static, it almost certainly connects to other cloud services such as databases or caches that are hosted on servers other than the ones on which main application is running. Connection strings are used to identify where to find the server running the service, what type of driver to use (Postgres, Redis, AMQP, etc.), and what credentials to access it with.

At first glance, they can look like nonsense and be difficult to parse, but the good news is, there’s a logic behind it all! Regardless of the service you’re using it to connect to, they all follow the same pattern:

driver://<username>:<password>@<server>:<port>/<database name>

Examples

I have a database on my local machine that I can connect to using this as my connection string:

postgres://adriennedomingus:@localhost:5432/test_database

You’ll notice there’s no password there — if a particular piece of the connection string is not relevant, it can be left blank, but the connectors must still be included (the : after adriennedomingus is there, even though it’s immediately followed by the @ sign). The port could also be left off in this example, since 5432 is the default port for Postgres.

--

--