Last week I had the privilege to be back at SAP Tech Ed in Las Vegas. I met a lot of wonderful people, one of them Craig Cmehil who suggested to me to continue writing some blogs in spanish. Also, I attended some wicked sessions ? During the opening keynote by Bernd Leukert, he had a couple of nice announcements. The first one was about the SCP FaaS service. The other one was about ABAP on the cloud. The main purpose of this blog is to focus on the FaaS as it pertains on the SCP.
the same blog can be found in spanish here
SAP Cloud Platform (SCP) Cloud Fundry (CF) – Function as a Service (FaaS)
What is it?
Function as a Service is a part of a Cloud Platform that allows companies to develop, run, and manage application functionality (tasks with smaller chunks of code) rather than the traditional big application, and infrastructure needed to run an app.
Why it makes sense?
it absolutely makes sense because as companies continue to explore and venture into Cloud Platforms and services, software continues to mature and take advantage of such services and resources, allowing them to grow/shrink as needed by the cloud infrastructure without the overhead cost of owning hardware. This becomes the pay what you use model. More SAP documentation can be found here as well as a nice architecture diagram shown on that site.
Next, I would like to showcase my experience of developing one of the functions as a service from my SCP trial account.
While using the SAP Cloud trial account, make sure you go to the CF region and create a new subaccount. Enable the Beta Features. Keep in mind this feature, Functions, is still not fully supported so we are going to look at it from a beta point of view.
Once the sub account is created (faasDev) then we can navigate into it
And Enable CF, in my case it uses the trial account settings.
Once it has been created, then you will notice on the right-hand section
Another pre-req we need to make sure we have is the SPACE. There is no space set by default so we need to create one.
I called it testFaas with its default settings.
At the subaccount level, we need to click on edit, in order to set the Entitlements. This section will allow us to create functions in the CF environment and eventually let us run our FaaS. I struggled in this section because I wasn’t able to find it easily, however, after reading a couple blogs and response from Maximilian Streifeneder I found it – thanks Maxi
after clicking on Edit, you can scroll down to functions and update the value from 0 to 1.
After saving those changes, we can go back to the SPACE and it should now show the Functions Service in the Service Marketplace
So let’s navigate into it and go into the instances section in order to create an instance of this service.
Create a New instance
Click next twice.. and leave the default wizard settings until you get to the step to assign a name and select Finish.
Read the official documentation for limits on how many functions per instance, how much resources and how many instances per account are allowed… again, this is in beta mode so documentation may be subject to change
When the Function service instance is created, it should look like so on your Dashboard.
You may need to grant access the CF instance to access your account
Once inside the Functions service, we can see the blank dashboard… so let’s take a look
Since we are in the Functions service, let’s create a Function. I will call it sayhelloworld and leave the default runtime (Node v8.1.0). more information about Nodejs can be found on the nodejs.org site.
Once the function is created, we can see the default handler (nodejs) code which is what will execute once this function gets called. This window looks like ….
And the bottom half of that screen looks like
Notice the different parameters, triggers, settings, secrets, etc… so I may be wondering what all this is.
If I go back to the functions page, I should expect to see my functions (1 in this case) similarly the triggers and secrets – I have not created any triggers / secrets at this time so let’s continue to explore
A trigger by definition is an object that will execute some operation (or function) so I clicked on the triggers page, and create new, provided a name and its type will be HTTP * other types can be timer (using chron job syntax – scheduled function) or event (binding a trigger to a function in order to react to a particular event from the enterprise event messaging service). I must select what function will get executed when this trigger is invoked
After creating the trigger, then the page shows the existing triggers
Since I selected an HTTP type trigger, I correctly assumed, I would get a URL to invoke it. I believe this may be the easiest way to consume a function via a URL, just like any other web service. So the different ways I normally test these services would be:
- Browser call – and let’s see what is in the network tab from the developer tools.. I am interested in seeing the execution time so I can see how well or bad this operation performs plus the response time… as this will eventually get called and I will get billed for the consumption of resources… yes that is the purpose of FaaS services.
Opening the network tab, we can see the size of the response (287 B) and the status 200 (HTTP OK)
Further, Analyzing the network tab header response we can see other properties of the response header.
And from postman (different free browser test tool – same response, 224ms and HTTP OK) I wonder why the difference in execution from the browser call and the browser extension.
note: there are 2 other ways (Event and Timer) to invoke the Function as a Service service, however, I am not showcasing them here for simplicity of my exercise.
Timer uses a chron job syntax for [Seconds, Minutes, Hours, Month, Year]
Events require a few extra steps to enable the Event driven message, Queue. These steps can be found here:
Finally, in the main page for the Functions Service, we can see the Dashboard.. within this page, we can see the logs for the specific functions we have defined. Notice that this log captures anything we specify in our handler function as console.log
Advantages of the function model architecture:
- Pay per resource/consumption – instead of paying for an entire hosting package
- Easy to start, scale, and deploy (this simple demo took me approx. 10 mins)
- Less time on building a lot of skeleton code – with a few clicks I was able to generate all the parts and it was time for me to fill in the function code.
Different from traditional software development:
- Different way of architecting software – think modular, scalable, microservices
- Resource utilization needs to be considered
- Independent deployments – so individual functions should be able to perform and complete a task
For additional Official documentation:
my personal note:
I am really liking the direction that SCP is going… offering FaaS similar to AWS and also using open source technology to accomplish this is really pushing the boundaries of latest technology, SAP embracing open source software and also making use of Cloud Foundry principles while continuing to improve and innovate in this area. well done SAP
I hope you can share you experiences with whatever function you decide to use as a service.
don’t forget to share your experiences