How to add new services to your Platform.sh application

Slideshow

View full screen

Video
Notes

As your application grows, new features may require adding new technologies and architectures.

Changing how search is handled on your site could require adding an Elasticsearch service to your cluster.

On Platform.sh, you can start by creating a new environment to test out the new feature.

On that environment's branch, add Elasticsearch to your project's services.yaml file. Here in that file we define the Elasticsearch service container under the name mysearch. We specify the elasticsearch type, a supported version, and finally the amount of persistent disk allocated to it.

Then update your .platform.app.yaml with a new relationship to access it. This new relationship, simply called elasticsearch, repeats the name we gave the service in the services.yaml file and includes that service's endpoint.

Commit those changes, and then push to deploy them on Platform.sh.

After the push, you can access the service locally via an SSH tunnel using the CLI command platform tunnel:open. We can run platform tunnel:info to discover the Elasticsearch service's connection credentials to use in your app.

Once the tunnel is open, you can send a request to the Elasticsearch server using that tunnel and the PORT parameter we found in the previous step.

All of your connection credentials for Elasticsearch reside in the PLATFORM_RELATIONSHIPS environment variable, which will then be used to connect to Elasticsearch.

When you're satisfied with the new Elasticsearch-dependent feature, you can share the development environment URL with others for review.

Then when you're ready to take the new feature live, merge the environment into master. Now production, as each new subsequent environment, will deploy with the the new Elasticsearch service.

Every bit of this configuration is explicitly detailed in your Platform.sh configuration files, which means going back to before the service is just a git revert away. That's what Infrastructure as code is all about.

Build your greatest ever app
Get started for free