Monday, 27 January 2020

Debug Azure Function in Visual Studio Code


Prerequisite -

Visual Studio Code (VS Code) is a code editor by Microsoft. Its an open source tool available for cross platform development so that an individual can get same experience across OS like Windows, Mac OS and Linux. 

Today we will try to debug an Azure Function (Java Script) in VS Code.

Step 1:- Use below command to initialize a new Function App

func init

Select worker runtime to node and language to javascript

Step 2:- Add new function by using command,

                func  new

Select template to Http trigger and leave function name as default. Hit enter

Step 3:- Run your function app using below command,

                func start

Note – Try it by openning the URL in any browser.

Step 4:- Use below command to open your app in VS Code.

                code .

Step 5:- Follow steps shown below to configuration VS Code to enable debugging.
  1. Hit Debug and Run
  2. Find DEBUG AND RUN -> Add Configuration
  3. launch.json file should be opened in editor.
  4. Select Node.js: Attach to Process
  5. Save changes
  6. Follow step 3 to start the function app
  7. Attached process as shown below,
  8. Add break point in index.js
  9. Try the function from any browser.
  10. The debugger should hit like,

Sunday, 26 January 2020

Getting Started with Azure Functions


Azure functions are Function as a Service (FAAS) offering from Microsoft Azure. It is a serverless compute service from the provider where user need not to worry about underlying deployment infrastructure because Microsoft as a cloud provider manages it for us.

Azure functions are good choice to perform independent stateless task. It has the ability to scale automatically based on traffic/demand. The documentation covers a lot, so we will not go into more details instead lets try to create a simple function.

Triggers – An azure function needs a trigger to perform its task. There are no of inbuilt triggers supported by Azure functions like HTTP Trigger, Queue Trigger, Blog Trigger etc.

Note – An azure function must have one and only one trigger associated to it.

Bindings – Azure function framework provides a way to read data into a function and write data from function to any data service. There are two major types of bindings,
  1. Input binding – Read data into an Azure function from any data service.
  2. Output binding – Write data to any data service from an Azure function.

Function.json – A file containing configuration details like trigger, bindings with respect to an individual Azure function. Every azure function has a corresponding configuration file that means every function app will have exactly one function.json with respect to each function.

There are multiple ways to create function apps like,
·         Azure Portal
·         Visual Studio
·         CLI
·         VS Code
We will look at the CLI and see that how easy it is to create a function app using Azure Function Core Tools.

Prerequisite:-
Step 1:- After installing the Core tools as mentioned above lets first verify it. Open a new instance of any command line tool (I am using power-shell but its completely your choice) and run below command,

                func

You should be able to see details like, Core Tool’s version, Contexts, Actions etc as shown below,

Step 2:- Create a new function app. Function app is a unit of deployment or a group of logically related functions, shares common configuration and scale together. Use below command to initialize a new Function App.

func init

There are multiple options worker runtime to select from but lets start with node and JavaScript as language.

Step 3:- Add new function by using command,

                func  new

Lets start with Http trigger template and you can also update function name to one you prefer, but I am leaving it to default. Hit enter,

Step 4:- Run your function app using below command,

                func start



Step 5:- Try hitting the URL from any browser. Please note that the default function generated by CLI expects an input(name) either in query string or request body.