Creating cost-effective solutions with Azure Functions

0
767

In the cloud world when you heard the term cost-effective what would comes to your mind? Is it IaaS Virtual Machines or PaaS services? Probably yes if you were not aware of the “Serverless”! What serverless? yes, you heard right, even the word makes you little confusing, of course, something similar that is happening in the world of the cloud.

With Serverless you can create cost-effective even driven applications – in Azure, we have Azure Functions, Logic Apps to do this task similarly in AWS you’ll find Lambda. When you compare with traditional PaaS offering such as Azure App Services with Azure Functions (AKA FaaS) the real difference is runtime execution strategy for your code. In Azure App Services you have to allocate dedicated App Service plan to run your application and then you have to pay a fixed monthly cost – this cost incurs even your app utilized the underlying hardware or not. However, when you use Azure Functions you’ll get a whopping one million (The first 400,000 GB/s of execution and 1,000,000 executions are free) executions for free every month and even more than the cost of execution after that will only be around $0.20 per execution. Isn’t this amazing?

Azure Functions pricing – https://azure.microsoft.com/en-us/pricing/details/functions/

Let’s see how easily we can create an azure function app using the Azure portal.

STEP -1

Login to your Azure portal and search for Azure Functions in all services and click add (+) new Azure Function button. You’ll see the following now.

Create a new resource group and give a name for the app name – app named should be globally unique. The publish method is really important when you’re writing the code – either you user docker container or maybe pure code you can select it here. When you’re using code you must select the runtime stack and the version of the runtime as well. But when you deploy with docker container you don’t need to select the runtime stack as it’ll run on top of the docker engine.

In this blog, I’m just focusing on running using code inside the Azure portal instead of using Visual Studio Code or Visual Studio.

Give all the details for the above step and click “Next: Hosting>”. You’ll see the following screen. Here we have to select what is the hosting method that we are going to use in our Azure Function.

Select the above configurations (Make sure to use the Windows as the Operating system and plan type as Consumption) and then click “Next: Monitoring>”. You may skip the monitoring step if you don’t want it. I’m skipping that too…! So go ahead and hit the create button and create the Azure Functions App!

STEP – 2

Once the Azure Function app has been deployed you can play around with it! now if it has been created go to the Azure Function app directly and you’ll see the following :

Now click “+New Function” the BIG button in the middle. Then you’ll see the following screen – select In-portal option from the screen. Then click the continue button at the bottom.

Now you’ll see the following screen. in this example I’m going to show you how to use the API/ Webhook pattern – however if you need timer triggers or any other triggers you can get them from the More templates option.

Once you select and click create you’ll see a screen like as follows.

Here’s where we can write the code for our API/Webhook. This is in C# – if you want you can use other languages that support. To line number 19 I’m going to add some changes as follows. (Save it before do anything)

return name != null
? (ActionResult)new OkObjectResult($”Hello, {name} How are you ?”)

Now click the top option – Get the function URL – to copy the URL for the Azure Function API endpoint. Copy the URL and then past it to the address bar and then add a quart string call “name” as follows followed by your name. Press enter and then you’ll see that the above Azure Function has been executed and return you with the response.

In this way, you can create stateless Web API applications or Webhook that can be triggered when the user requested the URL. One of these requests is one excitation of the Azure Function so thinking about 1,000,000 requests for the Web API and how it will act as backend API. Isn’t it Amazing? absolutely amazing!

So if you have specific applications that can leverage Serverless its good idea to go ahead with serverless so that you can reduce the cost during its runtime. In conclusion, you must remember that serverless is not going to suitable for all locations, however applying the strategy where appropriate you will save millions of dollars in the long run.

Comments

comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here