In the following the capabilities of the sub component Functions of the SAP Cloud Platform Serverless Runtime (in short: Functions) will be demonstrated. Functions provide a cloud-based serverless framework for the development of decoupled and resilient applications and integration flows (using SAP Cloud Integration) to support asynchronous communication principles. Direct integration with SAP S/4HANA Business Event Handling allows efficient development of innovative and scaling extensions.
This repository provides documentation and samples of how to implement functions (Node.js) on SAP Cloud Platform in the Cloud Foundry environment. Details on each sample application and the covered scenario are described in the table List of content and sample projects below.
For more details about Functions take a look at Functions on SAP Help portal.
Sample/Content | Scenario | Scenario Description |
---|---|---|
amqp-echo | Basic AMQP 1.0 example |
An echo function with messaging |
ce-coffee | Basic CloudEvents example |
A CloudEvents producing function attached to a CloudEvents trigger |
call-other-function | Basic example | A function calls another function |
hello-oauth | Basic OAuth example |
The function is triggred by an HTTP request and does OAuth validation of the token using a pre-defined public key |
hello-oauth-xsuaa | Advanced OAuth example using custom XSUAA |
The function is triggred by an HTTP request and does OAuth validation of the token using a custom XSUAA instance |
hello-secret | Basic example | A function extracts data from a secret |
hello-timer | Basic example | A function that is triggered according to a CRON expression based schedule |
qrcode-producer | Basic example | A function produces the current timestamp as QR code |
s4sdk | Advanced example | A function leverages the SAP Cloud SDK for JavaScript to interact with the BusinessPartner API exposed by an SAP S/4HANA system |
slack-classify-image | Advanced example, requires Slack integration | An image post in Slack triggers a function. The function classifies the image via SAP Leonardo |
weather | Advanced example, requires OpenWeatherMap account |
Two functions representing a simple web page that handles user input and displays the result |
kafka-producer | Advanced example, requires Kafka broker instance | A function is triggered by a message and produces a message on a Kafka topic |
To run the samples, make sure you have completed the initial setup first.
-
Install Node.js
Download and install Node.js(includes npm). The Node.js version must be >= 8.12.x.
-
Install xfsrt-cli
Download the binary either from Nexus or from the CP Tools Page.
-
Install faas-sdk
Add the SAP NPM Registry to your npm configuration for all
@sap
scoped modules.npm config set "@sap:registry=https://npm.sap.com"
Installation or update:
- Linux
sudo npm install @sap/faas -g
- Windows (as usual user)
npm install @sap/faas -g
Finally, run:
faas-sdk version
to test successful installation.
- Linux
-
Install CloudFoundry command line tools (CF CLI)
Download and install the Cloud Foundry CLI.
Run the command
cf login
, and login to your Cloud Foundry environment.Make sure your SAP Cloud Platform Serverless Runtime service instance and service key exist.
Further necessary configuration and settings are dependent on the specific sample and are documented there.
To download and install the samples just clone this repository using this command:
git clone https://github.com/SAP/cloud-function-nodejs-samples
For details on how to configure and run the samples please take a look into the README in the corresponding samples directory.
The file faas.json in each sample directory is used as a manifest. It defines secrets, functions and triggers for one single project.
For debugging purposes, the following template launch.json
can be adapted and used:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/examples/<specific_example>/node_modules/@sap/faas/lib/cli.js",
"cwd": "${workspaceFolder}/examples/<specific_example>",
"args": [
"run",
"-y",
"values.yaml"
]
}
]
}
This project is as-is with no support, no changes being made.
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the SAP SAMPLE CODE LICENSE AGREEMENT, v1.0-071618 except as noted otherwise in the LICENSE file.