Buy Me a Coffee

Buy Me a Coffee!

Monday, January 11, 2021

What's an Azure Function?

One of the top 3 items in our free list is something called a Function App.  It is a web application that is pure PaaS.  It lets you run code and get the responses back.  With the free tier, you get 1,000,000 requests per month.  Yes, one million requests per month for free!  There are some interesting limits though.  From the Microsoft page:

Azure Functions pricing

Azure Functions consumption plan is billed based on per-second resource consumption and executions. Consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GB-s of resource consumption per month per subscription in pay-as-you-go pricing across all function apps in that subscription. Azure Functions Premium plan provides enhanced performance and is billed on a per second basis based on the number of vCPU-s and GB-s your Premium Functions consume.

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

What that means is that you get 1 million requests, but you can't use the requests to calculate PI to 1 million digits with each call.  The total amount of CPU time and memory used impacts the number of calls you can make and stay within the free budget.  The amount you get for free is still extremely large because you are using excess resources.  You see, Azure Functions act sort of like Spackle.  You are using resources that open up between the larger, more expensive jobs.  

Let's try one out.  Create a new resource by clicking <create a resource>

Type function in the search box and choose Function App
Click <create>
Choose our existing resource group and type in the name of the function.  Then choose PowerShell Core as the Runtime stack and click on <review + create>

PowerShell is a cross platform scripting language.  It won't require a lot of code to do a lot of work.  Now just click on <create> and we will have our function
Once the deployment completes click on <go to resource>
Now we have our platform, so we need to put some code in it.  Click on <functions> in the left menu

Then click on <add> in the top middle

Leave the Development environment as Develop in portal for now and choose the HTTP trigger in the list and click <add>

Click on <code + test> in the left menu

We are going to leave the template alone for now.  If we had some code to add from our local machine we could click the <upload> button in the top to replace the template code
But for now, just click on the ellipsis (the three dots) and the click on <get function url>
A popup box will appear.  Click on <copy to clipboard>

And now paste the URL into a browser window.  Mine is
https://cheapsitefunction.azurewebsites.net/api/HttpTrigger1?code=<a big secret>==
with a key value in place of the a big secret that authenticates the request.  When I browse to the link I get

The highlighted text
This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.
is the output of our code.  You just ran a program in the cloud!  Ok, it didn't do much yet.  I hear you, and we will fix it.  For now, we are just trying out the different pieces and we will put them together later to see what we can build.  Stay Tuned!