Technical Articles
Exploring SAP Cloud Platform Functions – SCP CF FaaS – Functions as a Service | Serverless coding, use-cases, How-to’s with examples – Part 1
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.
- Create a SubAccount with “Enable Beta Features” checked.Functions is still in beta.SAP CP Trial Account is suffice https://account.hanatrial.ondemand.com.
- In the Global Account, under the “Entitlement” section, make sure you add the quota for the corresponding subaccount.
- 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
- Functions – The code to be executed when it is invoked by the corresponding trigger
- Triggers – As the name implies, a trigger is something which invokes the function and SAP CP currently offers 3 kinds of triggers.
- HTTP – An HTTP url through which the function can be invoked.
- Timer – Timer lets you schedule function using a cron pattern. For example: This pattern “0 * * * *” executes the function every hour.
- Event – Executes the function on an event received or published from the enterprise messaging service
- 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:
Let me know if you have any queries and please share your interesting findings as well! You can contact me on LinkedIn or Twitter or through any of the profiles mentioned in my site regarding the same! Until then stay tuned!
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.
Hi Sergio Guerrero !
Thanks ! 🙂 Many more use cases coming soon!
any idea, why my trail account may not have functions in the service market place ? see img atta
ched
Hi Sergio Guerrero
from my point of view there are only 2 root causes:
Could you please double check them? (probably screenshots)
Cheers,
Maxi
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.
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
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
Maximilian Streifeneder  any ideas?
Hi Sergio Guerrero !
I hope you were you able to set the entitlements ? I was away for a while sorry!
hi Hemchander, yes thank you very much.. your blog as well as help from others in the community i was able to find where i needed to enable it
Hi Hemchander,
After adding the quote we need to create the new Space "test" in the new account. Then only we will be able to go to Service Market Place. Please add this for the benefit of everyone.
Thanks and Regards
Dinesh Ghanta
Hi,
In case some, someone runs into this issue while creating the service instance:
Service broker error: Service instance name not provided
try this solution
https://answers.sap.com/questions/12664469/unable-to-create-service-instance-for-function-as-.html
Hi,
I am getting below error when instance is creating.
Service broker error: Service is deprecated.
Hi,
I'm new to cloud functions and EM so playing around a bit. I've set up an EM with 1 topic and can push messages on it with Postman API. I've created 2 event Functions which posts a simple console.log message and linked 2 Event triggers on the topic from the EM. I also created a third Function (again showing a simple console.log msg) with a trigger linked to the queue itself. Everything works fine, i can push a message to the topic which activates all 3 functions.
Now i have created the same exact thing on another EM queue with 2 topics (and with 4 functions) but this doesn't activate the functions. The messages are getting put onto the queue though.
If i try to put a message onto the first queue again via the topic (so my working example from before), it doesn't work anymore (but the messages are also getting put onto the queue).
any idea's on what could cause this??
kind regards,
Jasper vanhove