Connect to services

At this point you have configured your application’s services as well as its build and deploy process in your .platform/services.yaml and files. As an example, in your file you may have defined a relationship called database:

    database: "mysqldb:mysql"

which was configured in .platform/services.yaml with

    type: mysql:10.4
    disk: 1024

In order to connect to this service and use it in your application, exposes its credentials in the application container within a base64-encoded JSON PLATFORM_RELATIONSHIPS environment variable.

To access this variable you can install a configuration reader library

go mod edit

npm install platformsh-config --save

compile group: 'sh.platform', name: 'config', version: 2.2.0'


composer install platformsh/config-reader

pip install platformshconfig

and access the credentials of database


use Platformsh\ConfigReader\Config;

$config = new Config();
$credentials = $config->credentials('database');

from platformshconfig import Config

config = Config()
credentials = config.credentials('database')

const config = require("platformsh-config").config();
const credentials = config.credentials('database');

import Config;

Config config = new Config();
Credential cred = config.getCredential('database')

import psh ""

config, err := psh.NewRuntimeConfig()
// Handle err

credentials, err := config.Credentials("database")
// Handle err

or read and decode the environment variable directly.

relationships = JSON.parse(new Buffer(process.env['PLATFORM_RELATIONSHIPS'], 'base64').toString());
credentials = relationships['database'];


$relationships = json_decode(base64_decode(getenv('PLATFORM_RELATIONSHIPS')), TRUE);
$credentials = $relationships['database'];

import os, json, base64

relationships = json.loads(base64.b64decode(os.environ["PLATFORM_RELATIONSHIPS"]))
credentials = relationships['database']

In either case, credentials can now be used to connect to database:

  "username": "user",
  "scheme": "mysql",
  "service": "mysql",
  "fragment": null,
  "ip": "",
  "hostname": "",
  "public": false,
  "cluster": "rjify4yjcwxaa-master-7rqtwti",
  "host": "mysql.internal",
  "rel": "mysql",
  "query": {
    "is_master": true
  "path": "main",
  "password": "",
  "type": "mysql:10.2",
  "port": 3306

You can find out more information about Config Reader libraries on GitHub:

You can also find examples of how to connect to each of managed services in multiple languages in the Services Documentation.

Project configured, services connected - time to commit the changes and push your repository onto your project.