Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
christianlechne
Active Contributor

Introduction


I had the honor to attend SAP Inside Track Hamburg 2019 (sitHH) as a speaker and my talk was about side-by-side extensibility of an SAP System with Microsoft Azure focusing on the serverless options of that platform. I also demoed the local development and execution of Azure functions on a Windows machine.

Afterwards I had some discussion especially about the local development and the options you have. One interesting possibility is the usage of the Windows-Subsystem for Linux (WSL) as a sandbox-like environment on your windows machine. As the discussion was happing with only a few people at sitHH and as I am convinced that this is interesting for more developers, I decided to write this blog about this specific option.

Prerequistes


Basically, there is only one prerequisite: your Windows 10 system must be a 64-bit system and be at least version 1607 (anniversary update). I did all the following steps on a Windows 10 Pro 1909, however this should not make any difference.

Installation


Before staring with the development you have some things to install that I describe in the following sections.

Step 1 – Enable WSL in Windows


The WSL is an optional feature of Windows 10. So, you must explicitly enable this feature. You find the necessary PowerShell command here: https://docs.microsoft.com/en-US/windows/wsl/install-win10:



After that you must restart your PC. This is the only time this is necessary.

Attention: Currently the WSL2 is quite often quoted in the web, but this new version of WSL is not yet officially available. I used WSL1. If interested, you find more information about WSL2 here: https://docs.microsoft.com/en-US/windows/wsl/wsl2-index

Step 2 – Install the Ubuntu 18.04 LTS App on Windows


After that you are set to install a Linux app on your Windows system. Go to the Microsoft store and look for the Ubuntu 18.04 LTS app that is available for free and install that app:



The Linux system will be downloaded and after that you must enter a Linux username and password to finish the setup process. You can then access the Linux system via the Ubuntu terminal.

Remark: An alternative that I use is the new Windows Terminal App, also available via the Microsoft Store:



 

This terminal app gives you access to all shells on your system in a tabbed terminal fashion:


Step 3 - Install Packages in WSL


Next open a terminal on the Ubuntu system and do some housekeeping i.e. update the Linux system via apt-get update, apt-get upgrade, apt-get dist-upgrade and apt autoremove.

After that you need to install the following packages that are available in the official Ubuntu repos (no need for custom repos here):

  • Node via
    sudo apt-get install nodejs


  • NPM via
    sudo apt-get install npm




As we want to develop Azure functions, you also need to install the Azure Functions Core Tools in the WSL. The steps are described in the official documentation: https://docs.microsoft.com/en-US/azure/azure-functions/functions-run-local#v2

Be aware the there is a section about Linux comprising the Ubuntu and the Debian specific commands and you only need the Ubuntu part - do not just copy one command after the other (not that I would have done that wrong at any point in time ?)

After successful installation you have your local Azure functions runtime available in your Ubuntu system. You can check the version via
func -v


Step 4 - Install Visual studio Code and WSL Extension


I am quite sure that nearly everybody has Visual Studio code installed on the Windows system (yes on Windows, not on Ubuntu). If not, this is the time to do it. You can download it from here:

https://code.visualstudio.com/



When you start Visual Studio Code the system will prompt you to install the “Remote – WSL” extension as it recognizes that the feature is active. If not, please do so explicitly via the Visual Studio Code marketplace:



The basics are set to develop Azure Functions in Linux from Visual Studio Code on Windows. Sounds weird? It is not, the developer experience is super smooth … even without any involvement of Qualtrics ?.

Azure Functions “Hello World” on WSL … and on Windows


Let us get the party started. Go to a Linux Bash Shell and create a directory for our “Hello world” Azure Function:



And now some magic – start Visual Studio Code in the Ubuntu shell by typing:
code .

The system will automatically install the server part of Visual Studio Code in Ubuntu:



After that Visual Studio Code will start on Windows and connect to Ubuntu via the Remote WSL extension  as shown in the following screenshot:



This is awesome! As the Visual Studio Code server is in the Linux system and we started from scratch, we have no extensions available in VS Code:



So install the Azure Functions Extension of Visual Studio Code in the WSL via the marketplace:



After that we can start with the local development of Azure Functions. Go to the Azure Functions extension:



Create a new Functions project in the directory we just created in the Linux system :





Next choose the language. For this example use "JavaScript":



After that define the trigger, that kicks off the function. For this demo use the "HTTP trigger":



Next give your function a name:



In the last step you must specify the authorization level. For this demo scenario use “Anonymous” (do not do that in productive scenarios):



After that the system creates a skeleton of your Azure Function:



As you can see the files are in your Linux system, while you did all the development in Visual Studio Code on Windows (at least the UI is running there).

Okay, so now let us run the function by opening a shell in Visual studio code (that of course is a bash in the Linux system – in case I did not mention it yet: what a smooth experience!) and enter
func start

which kicks off the Azure Functions local runtime



After some beautiful ASCII art ...



... you will get an HTTP endpoint for you function, that you can call:



But wait a second, that is localhost in the Linux system … hmmm … okay let us click on it and see what happens. A browser opens … in windows … redirected to the Azure Functions runtime in Linux. Nice!



Congrats! You got your first function running in Linux on Windows!

But what about Debugging?  Set a breakpoint into your source in Visual Studio Code and press F5. The Azure Functions runtime will start, and the debugger will attach as usual:



If you now redo the call from the browser, your breakpoint will be hit in Visual Studio Code:



You guess it: smooth experience also for debugging. Now it is up to you to dig more into the options you have!

Summary


Motivated by the sitHH marketplace sessions I wanted to use this blog format as a medium to show you some, from my perspective, interesting stuff not directly linked to the SAP ecosystem. I hope you got a first impression how easy it is to set up a Linux environment within windows and use it for your local development (in my scenario with Azure Functions). When I first played around with this stuff, I was really impressed how easy it is to get things running and how frictionless all the parts are integrated. From my point of view this is a benchmark on how development should work locally and with access to remote environments. The remote access to WSL is only one example, you can do the same with containers. You find more information on that here: https://code.visualstudio.com/docs/remote/containers

Nothing more to say than: Enjoy your development journey with Visual Studio Code, Azure Functions and WSL!

P.S. If you are also interested in my talk, you find it here: