Published by Cole Francis, on Thursday, July 6, 2017
An Azure function is an ideal way to write discrete pieces of code in the cloud without concerning yourself with the machine and infrastructure that will support the code. Azure functions offer a variety of difference development language choices, including C#, Python, PHP, Node.js, and F#. Because Azure Functions live and run inside the Compute Stack, you only pay for the time that it takes for your code to run. What’s more, you get all the support and scalability without having to own or maintain an on-premises server.
Furthermore, Azure functions can run under the “Consumption Hosting Plan”, which means that you only get charged for the time the code spends running. It also supports NuGet and NPM Package Management, so you have access to all of your favorite templates and libraries. Additionally, it comes with integrated security, so OAuth providers, such as Azure AD, Microsoft Account, Facebook, Google, and Twitter are readily available.
What’s more, you can easily integrate with Azure services and SaaS offerings, including Azure Cosmos DB, Azure Event Hubs, Azure Mobile Apps (tables), Azure Notification Hubs, Azure Service Bus, Azure Storage, GitHub (through webhooks), on-premises (using Service Bus), Twilio (SMS messages).
What’s more, you can code your functions inside the portal, which I’ll do in this example, or you can set up continuous integration and deploy your code through VSTS and GitHub (and others). Azure Functions also use a “Pay per Use”, which means that you only pay for the amount of time your code executes.
In any event, in the following step-by-step example, I’ll be creating my very first Azure function.
The first step is to login to your Microsoft Azure Portal account. Once you’ve successfully done this, then click “New” on the left navigation bar.
When the “New” menu pops up, click on the “Compute” option in the list.
Once you click on the “Compute” item in the Marketplace selections, look for the “Function App” option in the Compute item list.
A new “Function App” creation dialogue box will ask you to name your application. I called mine functions-cfrancis2017. You can name your whatever you like. Also, keep the “Consumption Plan” selected as the “Hosting Plan”. Azure provides two types of pricing in this category, including the Consumption Plan and the App Service Plan. Here’s the difference between the two:
Once you’re satisfied with the name of your “Function App”, then click the Create button at the bottom of the dialogue box.
You should now be able to find your new App Service and Storage Account in the Azure Portal.
Clicking on your function allow you to inspect its details. You can even toggle your new Function App as a favorite by clicking on the star next to your new function.
Once you toggle it as your favorite, you can easily find it anytime you look through the Function Apps section of the Azure Portal.
Click on the following items to display more information about your new Function App or to drill down on the type of item you’d like to create under this category.
We want to create a new Azure Function that lives in our new Function App. So, just:
Click the “Run” button just to try it out. Once you’re satisfied with the results, try running the Azure Function remotely.
To run it remotely, click on the “</> Get function URL” selection to bring up the Azure Function URL. This is the restful service you will call to execute your new Azure Function.
Select the default (Function key) and review the results of the HTTP(S) call.
Do the following:
Now you can go back into the Azure Portal and review the results for the calls that you (or anyone else) makes to your new Azure Function.
From a primitive standpoint, that’s all there is to it. Of course, I’ll provide a more complex implementation of one in a future article.
Hi, I’m Cole Francis, a Solution Architect for The PSC Group in Schaumburg, IL. I’ve been successfully designing, developing, and delivering custom software solutions for an impressive and extensive list of well-branded clients for over twenty years.
Thanks for reading and keep on coding!
Categories: Azure,Azure Functions,Cloud,PSC