An app can talk to a service only if it is “attached” to it.

Prerequisite

Create service

You must create your service before you attach it to your app.

Attaching a service to an app simply entails exposing the service parameters like the URL and the credentials as runtime environment variables in the app.

This can be done either from the service detail page by going to the “Apps” tab,

services tab in app

In this form, you select the service you want to attach to, and configure how you want to expose your service.

Once the service is attached successfully, it will show up in the “Services” tab of your app page.

Attached services

There are 2 ways to expose a service via environment variables.

As a URL

The service will bind to the app as a url. Example: DATABASE_URL=postgres://shapeblock:shapeblock@db-postgresql/shapeblock.

Service attach as URL variable

As separate variables

Each parameter of the service would be a separate environment variable. The same service as above would entail 4 variables: DB_USER=shapeblock, DB_PASSWORD=shapeblock, DB_HOST=db-postgresql, DB_NAME=shapeblock.

Service attach as separate variables

It is possible to change the environment variable name in both cases after the service is attached, but the value cannot be changed. For example, DATABASE_URL in the above example can be changed to DB_URL after attaching the service.

It is not possible to change the default port number the service is exposed to. For example, Postgres can only be exposed on port 5432.

It is possible to attach any number of services to any number of apps.

Possible next steps

Deploy your app