table of contents

Crated on ;

sap btp

(formerly sap cloud platform)

sap btp is the platform as a service solution that sap provides, they rent you hardware operated by cloudfoundry or kyma (this is the OS that will be deployed in the hw), and you can deploy whatever you want there; they also give you sap services (sap hana db, sap uaa, etc) which you can connect with the cluster.

overview and arch

cloudfoundry

TL;DR it provides a huge level of abstraction for the developer to only push its app and have it running, without having to worry to much about infra.

You install cloudfoundry in all the hw of your cluster. Like installing kubelet in the machines, having an admin, workers and so on. The installation is out of the scope of this text.

When you push an application to the cluster, cloudfoundry will create a runtime environment in the cluster for the app to run. It basically creates a container that is called "Cell" in this context.

You can also connect SAP services to the cells.

kyma

You deploy k8s in your cluster, kyma is deployed on top k8s, kyma extends the applications running inside the pods. It gives them monitoring or authentication, and so on.

kyma gives and "application connector" for the app in your pod to be able to trigger serverless functions, and connect with 3rd party or SAP services.

Create a BTP trial account, open cockpit.

account management

There is a global account, inside that there are subaccounts and inside that there are spaces, inside those we have the applications.

You can go to "Entitlements" to see the services your subaccounts have access to, it will tell you in "units" say you have "1 unit" of "SAP HANA Cloud" this means you can only create 1 of it. These are defined by the license in the global account.

On each Space you can see the Services you want to add to your applications. Like you look for the service in the marketplace and add it to your space. Then you can manage it. Say you create a postgresql db, after creating it you can see the credentials and all that.

org level

There will be one or many global accounts (which are tied to the leasing) that will have multiple subaccounts.

You can divide the subaccounts by teams, so each team has a one or more subaccounts. Say you have a finance team, they can have 3 subaccounts, one for dev, qa and prod.

Inside each subaccount you will have different spaces for different applications.

hands-on

You need to install the cloudfoundry cli, you can use brew


brew install cloudfoundry/tap/cf-cli@8

basic commands


% cf version
cf version 8.18.0+fad4bcb.2026-03-04

To login you go to the subaccount, under the cloudfoundry info and pass it along.


% cf login -a 'https://api.cf.us10-001.hana.ondemand.com' \ # endpoint
    -o '156c6d83trial'  \ # org
    -s dev  \ # space
    -u '' # your email probably

It will also ask you for your password


API endpoint:   https://api.cf.us10-001.hana.ondemand.com
API version:    3.215.0
user:           [email protected]
org:            156c6d83trial
space:          dev

buildpacks

a buildpack is software that will check some source code and transform it into runnable artifacts. It will analyse and check the best way to build it.

You can list the available ones with


% cf buildpacks
position   name                          stack      enabled  locked
1          staticfile_buildpack          cflinuxfs4 true     false
2          java_buildpack                cflinuxfs4 true     false
3          nodejs_buildpack              cflinuxfs4 true     false
4          go_buildpack                  cflinuxfs4 true     false
5          python_buildpack              cflinuxfs4 true     false
6          php_buildpack                 cflinuxfs4 true     false

cf apps

remember you are logged into an space, most of this are similar to k8s stuff


cf apps # list apps
cf start|stop <app-name> # guess what it does
cf logs <app-name> (--recent)
cf scale <app-name> -i <number of instances>

deploy an app

You can deploy an app in different ways, the simplest one is inside your app repo just use


cf push <name of app>

cf will create the buildpack necessary.

You can create a manifest.yaml to setup how you want your app to run, like to set up specific stuff to overwrite.

Here is an example of a simple manifest.yaml


applications:
  - name: my-node-app-m-01
    memory: 256M
    path: ./
    buildpacks:
      - nodejs_buildpack

mta.yml (sap specific)

There is this SAP specific way of deploying an application, it is helpful because this is a good way to bind different sap services to your application.

You need to install a plugin onto cf in order to use it.


cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
cf install-plugin -f multiapps

After this you will have the deploy command available.


cf deploy

First we need to package the application, this is done with the mta builder tool, you need to install it. sap.github.io/cloud-mta-build-tool/download

After that you create a mta.yaml file, here is a simple example:


ID: d-01.demo.sample
_schema-version: 3.3.0
version: 0.0.1

modules:
  - name: my-node-app-01
    type: application
    path: ./
    parameters:
      buildpacks:
        - nodejs_buildpack
      memory: 512M
      tasks: # stuff to run when the app is put in cloudfoundry
        - name: task-abc-1
          command: npm install

Then you can create the package with mbt build, now a new directory will be created called mta_archives, if you look inside you will find a mtar file, which is your app with some extra files.

You can deploy the mtar file with


mta deploy mta_archives/your-file.mtar

This will talk with BTP upload the file, and deploy whatever you defined there.

binding service to app

First we need to create the service, you can create it from the cockpit, like going to service marketplace, finding the service and hit create or you can just use the cli. We will create a postgresql in this example.

Note: some services have a hyperscaler option which basically means that the installation/setup time is lower than usual but price is higher.


# -------------> <service name> <plan> <instance name>
cf create-service postgresql-db trial my-post-db

You can see the progress with the cf services command.

Now you need to create a key that your app will use at runtime to auth against the db, you can use the create-service-key command for it.


cf create-service-key my-post-db svc-key-2

how do we get this credentials from inside our code base?

First you need to bind the application to the service, that can be done manually in the UI, using cli, or you can also add the binding to the manifest.yaml so it gets bound from the start.

The latter is the standard way of doing it so here is an example


applications:
  - name: my-node-app-m-01
    memory: 256M
    path: ./
    buildpacks:
      - nodejs_buildpack
    services:
      - my-post-db

It is as easy as adding the service name there.

Now inside the codebase the credentials will be exposed in the env under a VCAP_SERVICES key json the structure looks smth like this:


{
    "VCAP_SERVICES": {
        "service-instance-name": [{
            "tags": ["user-created-tags"],
            "credentials": {
                "user": "user"
            }
        }]
    }
}

You can verify the structure by checking the env of your app cf env <app-name> there you will see how it looks.

You could load the env as usually, but if you are using npm, there is a nice package that helps the development of this. It will look something like this.


const xsenv = require("@sap/xsenv");
xsenv.loadEnv();
var xs_svcs = xsenv.getServices({
    "db-post-tags-02": {tag: "db-post-tags-02"}
});
var conn_service = xs_svcs["db-post-tags-02"]

You can query the services bound to the app by using tags. These are user created so you need to create the tag in your service first so this query can find it, again you can use the cli or the UI, it is as simple as doing this command.


cf update-service my-post-db -t "db-post-tags-02"

Now when you cf push your app, in the cockpit you will be able to see the binding, of the service and app, and inside the app you will be able to use the credentials.

By using the @sap/xsenv module, you can have a default-env.json file in your local workstation, to emulate how the env would look like, so you can test. The structure is the same as the json VCAP_SERVICES listed above.

table of contents

↑ go to the top