Setting up SAP WebIDE as development environment for SAP Cloud Platform Functions
I had earlier posted a blog series “React to events and connect 3rd Party systems using Serverless services & Open Connectors” on how to use the new SAP Cloud Platform Functions service in conjunctions with other serverless services. In this blog post, I will focus on how to use SAP WebIDE to develop and deploy functions.
Please note that this capability is still not yet available in SAP WebIDE trial environment. I will update this blog post when it is made available for everyone to try.
Setup Trust between Environments
SAP WebIDE is in the Neo environment of SAP Cloud Platform and Functions service resides in the Cloud Foundry environment. In order for WebIDE to communicate with the Functions service, trust needs to be established between the two environments
Navigate to the Neo environment and under Security > Trust, change the configuration type to custom and download the metadata file. Ensure that the Principal Propagation is enabled. Once the file is downloaded, change the Configuration type back to default and save your changes.
Navigate to the Cloud Foundry subaccount and under Security > Trust Configuration, add a new Trust Configuration and provide the metadata file downloaded earlier. You can also follow the instructions to setup the trust from the SAP Help documentation.
Create a Function Instance
Now that we have configured the trust between the environments, its time to create an instance of a function. Navigate to the “Service Marketplace” and click on Functions tile.
Create a new instance and accepts the defaults. You would need to provide a name for your instance in the last screen. In the below example, I have provided a name as “CFunction”
Select the newly created instance and navigate to the “Service Keys” to create a service key. You will need to note down the url, clientid and clientsecret as highlighted below.
Creating a destination
We would need to create a destination which will be later referenced by SAP WebIDE. In the Neo environment, navigate to Connectivity> Destinations and create a new entry. The proxy type needs to be “Internet” and Authentication would be “OAuth2SAMLBearerAssertion”.
Provide the values as explained below:
- URL: This value would be the same as the URL parameter in the instance service key
- Audience: To obtain the audience, you would need to download an XML file. Open your browser and provide a URL in the below format. This would require details of your Cloud Foundry subaccount.
In my scenario, subdomain is “cal” and domain is “eu10.hana.ondemand.com”. My complete URL is “https://cal.authentication.eu10.hana.ondemand.com/saml/metadata”
This is the XML file I received. Extract the entityID and provide its value for audience.
3) Client Key: This value needs to be the Client ID obtained in the Service Key
4) Token Service URL: In the downloaded XML file, look for the tag AssertionConsumerService and the location property which contains the value “oauth/token/”. I have highligted this in the above screenshot. Copy the entire location value.
5) Token Service User: This value needs to be the Client ID obtained in the Service Key
6) Token Service Password: This value needs to be the Client Secret in the service Key
Apart from this, you would also need to add two properties –
WebIDEEnabled = true
WebIDEUsage = faas_api
Save your destination.
Development using SAP WebIDE
Launch the SAP WebIDE FullStack service and enable the “SAP Cloud Platform Functions (Beta)” feature from the preferences.
After the reload of WebIDE, you should now be able to see a new project template for SAP Cloud Platform Functions.
Follow through the wizard by providing a project name and an appropriate name for the function.
The wizard also guide you in the creation of a trigger. In the below example, I have selected a HTTP trigger for the function.
Once the project is created, you will be able to see the folder structure for Functions and Triggers. You can update the index.js file with you business logic.
If you have to add any nodejs dependencies, you can update the package.json file as shown below.
Finally, you can right click the project and deploy your function.
Select the destination was was created following the above steps.
This will instantly deploy the functions to the Cloud Foundry environment. You should be able to verify this in your log console.
In order to check if the artefacts have been deployed correctly, you can now navigate to your functions instance in the Cloud Foundry environment and view the function code along with the trigger assignments.
You can now test the function by triggering a HTTP event with parameters. Copy the URL from the HTTP trigger and use it in a REST Client. Notice the body content with JSON object.
After testing the function, you should be able to view the logs with the console logs.
I hope this gave you some good insights as to how you can now use SAP WebIDE to write function codes.This can now facilitate the handling of source code versions etc.
Nice one! As always I really appreciate the step by step pictures.
Thanks. Nicely detailed.
Blogs like this removes entry barrier and stimulate folks to try out. I’m going to try today.
Thanks. Keen to hear your experience - may be as a blog post 🙂
Hi Murali Shanmugham
I was able to invoke the Function that I created in Functions dashboard and was also to deploy functions and triggers from WebIDE.
Will post a blog after a customer engagement on this topic 🙂
Thanks. Looking forward.