Cloud Vendor | Microsoft Azure |
Proficiency Level | Cloud Enthusiast |
Tags | App ServiceAzure FunctionServerless |
Summary
In this lab, you will create an Azure serverless app using Azure Functions. The serverless app will use an HTTP trigger and will be publicly accessible via its URL. When invoked, the app will reply with the phrase: “Hello, [your_name]! I am a serverless app!”, where [your_name] will be replaced with the name you pass as a query string parameter to the app.
Each exercise below builds upon the previous one. You should start each new exercise from the last step of the previous exercise unless it is explicitly written otherwise.
Learning Objectives
After completion of this lab, you will be able to:
- Create Azure serverless apps
- Use HTTP to trigger the execution of your serverless app
- Modify the code of the serverless app to reply with the intended message
- Stop the serverless app to avoid unwanted charges
Prerequisites
To complete this lab, you will need the following:
- Reliable internet connection
- A work, school or personal Microsoft Account used to access Microsoft Azure Management Portal
- A subscription for Microsoft Azure
Exercise #1: Create an Azure Function App Resource
In this exercise, you will create an Azure Function App Resource. Azure Functions are hosted within the App Service cloud service offered by Microsoft.
Steps
- Sign into the Microsoft Azure Management Portal at http://portal.azure.com using your Microsoft Account
- Click on
in the upper left corner right under the logo
- In the search box search for Function App and press Enter
- On the next screen, click on the
button
- On the Basics tab in section, Project Details fill in the following information
Subscription →<select your Microsoft Azure subscription>
Resource group →Create new
Resource group name (the text field in the pop up) →computelab02-rg
- On the Basics tab in section, Instance Details fill in the following information
Function App name →computelab02-[first_and_last_name]-fun
Runtime stack →.NET Core
Region →West US 2
Where[first_and_last_name]
is replaced with your first and last name in lower case and no spaces - Click on the
button
- On the Hosting tab, leave everything as default
- Click on the
button
- On the Monitoring tab, leave everything as default
- Click on the
button
- On the Tags tab, add the following tags:
Role →http serverless
Lab →computelab02
Owner →<your name>
OwnerEmail →<your email>
- Click on the
button
- Review the summary and click on the
button
- Wait until the deployment is completed
- Once the deployment is completed, click on
in the left-hand menu list
computelab02-rg
resource group in the list and click on it
the - Milestone step: At this point, you have learned how to create a serverless app in Microsoft Azure using Azure Function App. Note that although you requested the creation of a single resource, multiple were created. Verify that you have the following resources in your
computelab02-rg
resource group:
ASP-computelab02rg-<some_letters_and_numbers>
App Service Plan
computelab02-fun
Application Insights
computelab01-fun
App Service
storageaccountcomput<some_letters_and_numbers>
Storage account
Exercise #2: Create an Azure Function
In this exercise, you will create an Azure Function. Azure Function is the serverless service offered by Microsoft.
Steps
- Click on the
computelab02-fun
App Service resource - On the Overview screen, click on the
button
- On the Azure Functions for .NET – getting started screen, select
for the Choose a Development Environment step and click on the
button
- On the Azure Functions for .NET – getting started screen, select
for the Create a Function step and click on the
button
- Milestone step: At this point, you have learned how to create an Azure Function with HTTP trigger in your Azure Function App. You can create multiple functions in the same App, each with different triggers.
Exercise #3: Modify the Function Code and Test the App
In this exercise, you will modify the Function code to reply with “Hello, [your_name]! I am a serverless app!”, where [your_name] will be replaced with the name you pass as a query string parameter to the app and test the app.
Steps
- In the code editor field, find the following line (line 19):
? (ActionResult)new OkObjectResult($"Hello, {name}")
- Change the line to the following:
? (ActionResult)new OkObjectResult($"Hello, {name}! I am a serverless app!")
- Click on the
button on top of the code editor
- Once the saving is complete, click on the
button on top of the code editor
- Copy the URL from the pop-up, and open a new browser window
- Paste the URL in the browser’s address field and add the following to the end:
&name=[your_name]
where
[your_name]
is your name. The desired text will appear in the browser window. - Milestone step: At this point, you have learned how to modify the code for Azure Function with HTTP trigger and test your changes.
Exercise #4: Stop the Function App
In this exercise, you will stop the Function App to prevent unwanted use and save on cost.
Steps
- Click on
in the left-hand navigation
- Click on the
button in the Overview tab to stop the Function App
- Milestone step: At this point, you have learned how to stop the Function App to prevent unwanted use and save on cost.
Last Update: October 4, 2019
You must be logged in to post a comment.