Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
Creating a Service (Gateway) in Cloud Foundry (Part 1)

One of the exciting things in Cloud Foundry is the possibility to connect your app to different services.

The interesting aspect about services is actually not the service itself. That can just be a regular CF app that provides some functionality, e.g., an app that takes photos, resizes and returns them. The key to getting that app used by other apps in CF is the so called ‘service gateway’. The service gateway does the brokering between the cloud controller and the app to make the service available.

A service gateway itself is rather simple. It needs to support 4 basic actions: bind/un-bind and provision/un-provision. Technically speaking it only needs to support binding and provision if unbinding/un-provisioning are not crucial for your service.

This can be a simple sinatra app that responds to “/gateway/v1/configurations” and “/gateway/v1/configurations/:service_id/handles”.

Advertising the service

The developer needs to provide a mechanism that advertises the service offering to the cloud controller. To do this several endpoints on the cloud controller have to be called to make it aware of the new offering. In this example we call it the CloudControllerAdvertiser.

It needs to perform 3 main functions.

1) Query the cloud controller for a list of services.
2) Advertise services and plans
3) Figure out which services are already registered.

The source code file can be found here: cloud_controller_advertiser.rb

Getting the service to run

To tie it together the CloudControllerAdvertiser needs to be run similar to this.
This can happen in the configure block of the gateway sinatra app or in an initializer.

gw_config = # get config infor for custom gateway
config = gw_config.config
uaa_token = # get a valid uaa token
cloudcontroller_advertiser =,uaa_token)
vcap_application = JSON.parse(ENV['VCAP_APPLICATION'])

service_config = gw_config.service_config
service_config[:url] = 'http://' + vcap_application['uris'][0]
service_config[:label] = vcap_application["name"]
service_config[:unique_id] = "#{service_config[:label]}-#{service_config[:version]}"
service_config[:plans].each do |name, p|
  p[:unique_id] = "#{service_config[:unique_id]}-#{name}"
service_offering =

registered_services = cloudcontroller_advertiser.list_services_with_plans
cloudcontroller_advertiser.resolve_service(registered_services, service_offering)
guid = cloudcontroller_advertiser.advertise_service(service_offering)
cloudcontroller_advertiser.advertise_plans(guid, service_offering.plans)

This should be pretty much all you need to get started with a service.
Remember to generate your auth token in the cloud controller. This and more details on service creation a documented here: CF service docs

In the second part of this article I describe how to bind the service to an app and make use of it.

Share This