Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

SAP-archive/cloud-function-nodejs-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Important Notice

This public repository is read-only and no longer maintained. For the latest sample code repositories, visit the SAP Samples organization.

Functions Node.js - Samples for SAP Cloud Platform Serverless Runtime

REUSE status

Description

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.

List of content and sample projects

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-world-jwt-auth OAuth based token validation by HTTP trigger A valid JWT has to be presented to an HTTP trigger before the function can be triggered
hello-oauth Basic OAuth example The function is triggered 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

Requirements

To run the samples, make sure you have completed the initial setup first.

  1. Install Node.js

    Download and install Node.js(includes npm). The Node.js version must be >= 8.12.x.

  2. Install xfsrt-cli

    Download the binary either from Nexus or from the CP Tools Page.

  3. 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.

  4. 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.

Download and Installation

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.

Debugging using Visual Studio Code

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"
            ]
        }
    ]
}

Support

This project is as-is with no support, no changes being made.

License

Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

Releases

No releases published

Packages

No packages published