Deploy a CAP Business Service to SAP Business Technology Platform
This tutorial shows you how to deploy your SAP Cloud Application Programming Model (CAP) application to SAP Business Technology Platform (BTP), Cloud Foundry environment using SAP HANA Cloud service.
Overview
You will learn
- How to deploy your CAP business service on SAP BTP and bind appropriate service instances. See the Developer Guide for Cloud Foundry for more details
Prerequisites
Prerequisites
- You’ve finished the tutorial Create a CAP Business Service with Node.js using Visual Studio Code.
- If you don’t have a Cloud Foundry Trial subaccount and dev space on SAP BTP yet, create your Cloud Foundry Trial Account with US East (VA) as region and, if necessary Manage Entitlements.
- You’ve downloaded and installed the cf command line client for Cloud Foundry as described in the tutorial Install the Cloud Foundry Command Line Interface (CLI).
- You’ve downloaded and installed the MBT Built Tool.
- You’ve downloaded and installed the MultiApps CF CLI plugin.
- You have to use an existing SAP HANA Cloud service instance or set up a new SAP HANA Cloud service instance to deploy your CAP application.
Steps
Intro
It’s now time to switch to SAP HANA as a database and prepare your project for an MTA deployment to SAP BTP Cloud Foundry. To continue with this tutorial you need to use an existing SAP HANA Cloud service instance or set up a new SAP HANA Cloud service instance to deploy your CAP application.
Your SAP HANA Cloud service instance will be automatically stopped overnight, according to the server region time zone. That means you need to restart your instance every day, before you start working with your trial.
If
cds watchis still running in VS Code, choose Ctrl + C in the command line to stop the service.To prepare the project, execute in the root level of your project in VS Code:
Shell/Bashcds add hana,mta,xsuaa,approuter --for production--for productionadds all configuration added by this command in thepackage.jsonfile into acds.requires.[production]block.hanaconfigures deployment for SAP HANA, so a data source of typehanais added in thecds.requires.[production].dbblock. See section Node.js configuration in the CAP documentation for more details.mtaadds themta.yamlfile. This file reflects your project configuration.xsuaacreates anxs-security.jsonand also the needed configuration in themta.yamlfile. An authentication of kindxsuaais added in thecds.requires.[production].authblock.approuteradds the configuration and needed files for a standalone AppRouter so that the authentication flow works after deployment.Learn more about those steps in the Deploy to Cloud Foundry guide in the CAP documentation.
Update your dependencies, as with the previous command you added some dependencies to your
package.json.Shell/Bashnpm update --package-lock-only(Optional) Following this tutorial strictly, you don’t have an own UI yet in your project. To enable the index page with SAP Fiori preview, add the following configuration in the
package.jsonof yourmy-bookshopproject in VS Code:JSON"cds": { "fiori": { "preview": true }, "server": { "index": true }, }server.index:trueenables the generated index page also inproductionmode as you saw it in your local application in the previous tutorial in step 4 when usingcds watch.fiori_preview:trueenables SAP Fiori preview in the same way. These features are meant to help you during development and should not be used in productive applications.
The Cloud Foundry API endpoint is required so that you can log on to your SAP BTP Cloud Foundry space through Cloud Foundry CLI.
Go to the SAP BTP Trial Cockpit and choose Go To Your Trial Account.

business technology platform cockpit view From the Account Explorer overview navigate to your subaccount.

subaccount tile From your subaccount copy the Cloud Foundry Environment API Endpoint value.

CF API endpoint value Go back to VS Code to the command line. Authenticate with your login credentials using the following command:
Shell/Bashcf loginFor this you need the cf command line client, see the prerequisites.
This will ask you to select Cloud Foundry API, org, and space.
The API endpoint is taken by default. If you want to change the API endpoint use
cf api <CF_API_ENDPOINT>to change the API. Replace<CF_API_ENDPOINT>with the actual value you obtained in the previous step.If you don’t know whether you’re logged on to Cloud Foundry or if you’re wondering to which Cloud Foundry org and space are you logged on, you can always use
cf targetin a terminal to find out.
Make sure that your SAP HANA Cloud instance is running, see Prerequisites, before you go on with this step.
SAP provides an application format that respects the single modules and their technologies and keeps those modules in the same lifecycle: Multitarget Application
The MBT Build tool uses the mta.yaml file that has been created using cds add mta before, to build the deployable archive. The MultiApps CF CLI plugin adds the deploy command and orchestrates the deployment steps.
In the previous step, you identified your API endpoint. If that has a format like
...us10-001..., you need to add the following configuration to yourxs-security.json:JSON"oauth2-configuration": { "redirect-uris": ["https://*.us10-001.hana.ondemand.com/**"] }For other API endpoints you’d need to adapt it accordingly.
In VS Code, in the root of your project, execute the following command to build the archive.
Shell/Bashmbt build -t gen --mtar mta.tarFor this you need the MBT Build Tool, see the prerequisites.
The
-toption defines the target folder of the build result as thegenfolder of your project. As part of this build implicitlycds build --productionis executed. This implicit build uses then all the configuration you’ve added in the step 1.2 when using--for production.Deploy the archive using
cf deploy.Shell/Bashcf deploy gen/mta.tarFor this you need the MultiApps CF CLI plugin, see the prerequisites.
During deployment all needed service instances are created and the applications as well as database artifacts are deployed.
This process takes some minutes. In this one step the archive is uploaded to Cloud Foundry, service instances are created, the applications are staged, and then deployed to their target runtimes.
If your deployment fails during deploy of
my-bookshop-db-deployer, make sure that your IP address is configured for connections to SAP HANA Cloud. Or allow connections to all IP addresses at your own risk. We recommend to revert that setting after you’ve completed the tutorial.In the deploy log, find the application URL of
my-bookshop:Shell/BashApplication "my-bookshop" started and available at "[org]-[space]-my-bookshop.cfapps.[region].hana.ondemand.com"This is the URL of the AppRouter, which enforces the authentication flow.
Open this URL in the browser and try out the provided links, for example,
/odata/v4/catalog/Books. Application data is fetched from SAP HANA. If enabled in step 1.4 you can also try the Fiori preview.
application preview
What you achieved
You’ve deployed your CAP application as multitarget application including deployment to SAP HANA Cloud, using the standalone AppRouter, and using authentication (XSUAA). Congratulations!
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.