My First Azure Function
Geeking Out

Our office is filled with experts, and they love writing about technology. There is so much to learn! Explore our insights through our blogs. Learn more about our thought leaders >

Back to Blogs >>

Published by Cole Francis, on Thursday, July 6, 2017

Main

BACKGROUND

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.

STEP 1

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.

Step1

STEP 2

When the “New” menu pops up, click on the “Compute” option in the list.

Step 2

STEP 3

Once you click on the “Compute” item in the Marketplace selections, look for the “Function App” option in the Compute item list.

Step3

STEP 4

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:

  • Consumption plan – When your function runs, Azure provides all of the necessary computational resources. You don’t have to worry about resource management, and you only pay for the time that your code runs.
  • App Service plan – Run your functions just like your web, mobile, and API apps. When you are already using App Service for your other applications, you can run your functions on the same plan at no additional cost.

Step4

STEP 5

Once you’re satisfied with the name of your “Function App”, then click the Create button at the bottom of the dialogue box.

Step5

STEP 6

You should now be able to find your new App Service and Storage Account in the Azure Portal.

Step6.png

STEP 7

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.

Step7

STEP 8

Once you toggle it as your favorite, you can easily find it anytime you look through the Function Apps section of the Azure Portal.

Step8

STEP 9

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.

Step9

STEP 10

We want to create a new Azure Function that lives in our new Function App.  So, just:

  1. click on (+) next to the “Function” item.
  2. Choose the scenario you want.  I chose a “Webhook + API”
  3. Click on the “Create this function” button.

 

Step11

STEP 11

After you click on the “Create this function” in the previous example, the following code block will automatically display in the language you chose.  I chose JavaScript as my Webhook.

Step12

STEP 12

Click the “Run” button just to try it out.  Once you’re satisfied with the results, try running the Azure Function remotely.

Step13

STEP 13

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.

Step14

STEP 14

Select the default (Function key) and review the results of the HTTP(S) call.

Step15

STEP 15

Do the following:

  1. Paste the link you just copied into a mainstream browser of your choice.
  2. Click the “Enter” key to navigate to the URL.
  3. Review the results.  They’re perfect!

Step16

STEP 16

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.

Step17

SUMMARY

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

Original Post: https://mobiusstraits.com/2017/07/06/my-first-azure-function/