Skip to Content

Following the recent announcements at SAP TechEd, I was delighted to know that the support for Functions (that enables serverless computing) is available as Beta in SAP cloud platform. Although FaaS (Functions as a service) has been in the existence already – AWS Lambda, Google Cloud functions etc., it’s adoption into the SAP Cloud Platform is seen as a great welcome gesture!  Not only does it add on to the arsenal of features that’s already present, it goes hand-in-hand with the microservices architecture, cloudfoundry adoption and the latest CAP model.

I am planning to cover this feature in Parts. The first part being a general intro and a quick ‘hello world’. More interesting stuff with FaaS is coming ahead. Make sure you stay tuned to this series ! 🙂

Without spending much time describing the stuff, let’s get into some action. There are 3 key things that you should note while trying this out.

  1. Create a SubAccount with “Enable Beta Features” checked.Functions is still in beta.SAP CP Trial Account is suffice https://account.hanatrial.ondemand.com.
  2. In the Global Account, under the “Entitlement” section, make sure you add the quota for the corresponding subaccount.
  3. Stick to using node.js core libraries in functions. There is a memory limitation for each function (~500MB), which might be removed in the future.

 

By default, we have one unassigned quota.

 

 

Once the initial subaccount setup, space creation and quota allocation is done, you can navigate to the Service Marketplace. Under the Service Marketplace, you will see Functions.

 

You can create a instance directly from here using Create New Instance button. For now, we are not specifying any external parameters and we skip the optional fields. Provide an instance name.

In the upcoming posts, I will explain how FaaS can be created using SAP WebIDE Full Stack as well.

The service instance would be created almost instantly ! You can go to the Functions Designer dashboard by clicking on the icon under the Actions column. The Function designer lets you create

  1. Functions – The code to be executed when it is invoked by the corresponding trigger
  2. Triggers – As the name implies, a trigger is something which invokes the function and SAP CP currently offers 3 kinds of triggers.
    1. HTTP – An HTTP url through which the function can be invoked.
    2. Timer – Timer lets you schedule function using a cron pattern. For example: This pattern “0 * * * *” executes the function every hour.
    3. Event – Executes the function on an event received or published from the enterprise messaging service
  3. Secrets – It is needed to create event based triggers. Basically it contains the credentials and service instance information of the enterprise messaging service.

 

You can create a new function using the “Create function” command. By default, it would have a Hello World code. However, we need to attach a trigger to execute it.

Under the Triggers tab, you can create a simple HTTP trigger and select the function name to execute.

Upon successful creation, you’d have a HTTPS url which you can open in the browser.

There it is ! A simple hello world app that we never coded. It was all a bit of setup and configurations done in minutes to have this running.

However, let’s not get carried away by the simplicity. In order to know how it works, I’ve added a specific page from documentation which will be handy when you start developing further. It is detailed further in the Functions programming model over here

Let’s play around with the event parameters a bit. The guide states the following:

Let’s print the request headers.

module.exports = {
    handler: function(event, context) {
        console.log(event.extensions.request.url);
        return JSON.stringify(event.extensions.request.headers);
    }
}

Here we go ! Make sure you “Save and Deploy” the code every time you make the changes.

Play around with the feature and let me know your interesting findings ! I will be covering the use-cases for FaaS in-depth in the next post. Stay tuned ! 🙂

References:

  1. Getting Started with SAP CP Functions (Beta)
  2. Official Documentation

 

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Sergio Guerrero

    Hemchander,

    thank you for sharing this detailed blog. It seems like it is the first one related to FaaS… I look forward to reading more like this one. i will also try to come up w one soon.

    (1) 
        1. Sergio Guerrero

          thanks for the prompt response Maxi …

           

          the account i set beta enabled on the first step as described by Hemchander. I tried on 2 diff trial accounts I have. Neither of them showed the functions section.

          what additional steps should i do on the The Entitlement sections.

          (0) 
          1. Maximilian Streifeneder

            I assume that you’ve missed this step:

            not sure if I understand you correctly, If you’ve done the entitlement step.

            When your new subaccount is created, go back to your global account, Click on “Edit” on top of the Entittlement page and set the quota for “Functions” to 1 for the recently created subaccount. After that your subaccount should show the “Functions” tile in the according Service Marketplace.

            If it still doesn’t work, could you please post screenshots of:

            1) your subaccount (there should be a “Beta” right after your subaccount name in the subaccount overview of your global account)
            2) your quota allocation in the entitlement sections
            3) your service marketplace after that

             

            (1) 
        2. Sergio Guerrero

          actually, i see the missing step: https://blogs.sap.com/2018/10/02/getting-started-with-sap-cloud-platform-functions-beta-in-a-serverless-environment/

          the entitlement needs to click on Edit … in order to change the functions from o  to 1

          (1) 

Leave a Reply