lab | ||||
---|---|---|---|---|
|
Given the dynamic nature of Microsoft cloud tools, you might experience Azure user interface (UI) changes after the development of this training content. These changes might cause the lab instructions and lab steps to not match.
Microsoft updates this training course when the community brings needed changes to our attention; however, because cloud updates occur frequently, you might encounter UI changes before this training content updates. If this occurs, adapt to the changes, and then work through them in the labs as needed.
In the lab you will build http triggered and schedule triggered functions in-portal. Final Http-triggered function will be triggered from console and retrieve the file from storage account.
Find the taskbar on your Windows 10 desktop. The taskbar contains the icons for the applications that you'll use in this lab:
-
Microsoft Edge
-
File Explorer
-
Windows Terminal
- On the taskbar, select the Microsoft Edge icon.
- In the open browser window, go to the Azure portal (https://portal.azure.com).
- Enter the email address for your Microsoft account, and then select Next.
- Enter the password for your Microsoft account, and then select Sign in.
Note: If this is your first time signing in to the Azure portal, you'll be offered a tour of the portal. If you prefer to skip the tour, select Get Started to begin using the portal.
-
In the Azure portal's navigation pane, select All services.
-
On the All services blade, select Storage Accounts.
-
On the Storage accounts blade, get your list of storage account instances.
-
On the Storage accounts blade, select Add.
-
On the Create storage account blade, observe the tabs on the blade, such as Basics, Tags, and Review + Create.
Note: Each tab represents a step in the workflow to create a new storage account. You can select Review + Create at any time to skip the remaining tabs.
-
Select the Basics tab, and then in the tab area, perform the following actions:
-
Leave the Subscription text box set to its default value.
-
In the Resource group section, select Create new, enter Serverless, and then select OK.
-
In the Storage account name text box, enter funcstor[yourname]**.
-
In the Location list, select the (US) East US region.
-
In the Performance section, select Standard.
-
In the Account kind list, select StorageV2 (general purpose v2).
-
In the Replication list, select Locally-redundant storage (LRS).
-
Select Review + Create.
-
-
On the Review + Create tab, review the options that you specified in the previous steps.
-
Select Create to create the storage account by using your specified configuration.
Note: On the Deployment blade, wait for the creation task to complete before moving forward with this lab.
-
In the Azure portal's navigation pane, select All services.
-
On the All services blade, select Storage Accounts.
-
On the Storage accounts blade, select the funcstor[yourname] storage account instance.
-
From the Storage account blade, find the Settings section, and then select Access keys.
-
From the Access keys blade, select any one of the keys, and then record the value of either of the Connection string boxes.
Note: You'll use this value later in the lab. It doesn't matter which connection string you choose. They are interchangeable.
-
In the Azure portal's navigation pane, select the Create a resource link.
-
From the New blade, find the Search the Marketplace text box.
-
In the search box, enter Function, and then select Enter.
-
On the Everything search results blade, select the Function App result.
-
On the Function App blade, select Create.
-
Find the tabs on the Function App blade, such as Basics.
Note: Each tab represents a step in the workflow to create a new function app. You can select Review + Create at any time to skip the remaining tabs.
-
On the Basics tab, perform the following actions:
-
Leave the Subscription text box set to its default value.
-
In the Resource group section, select Use existing, and then select Serverless in the list.
-
In the Function app name text box, enter funclogic[yourname]**.
-
In the Publish section, select Code.
-
In the Runtime stack drop-down list, select Node.js.
-
In the Region drop-down list, select the East US region.
-
Select Next: Hosting.
-
-
On the Hosting tab, perform the following actions:
-
In the Storage account drop-down list, select the funcstor[yourname]** storage account that you created earlier in this lab.
-
In the Operating System section, select Windows.
-
In the Plan type drop-down list, select the Consumption option.
-
Select Review + Create.
-
-
On the Review + Create tab, review the options that you selected during the previous steps.
-
Select Create to create the function app by using your specified configuration.
Note: Wait for the creation task to complete before you move forward with this lab.
In this exercise, you created all the resources that you'll use for this lab.
-
In the Azure portal's navigation pane, select the Resource groups link.
-
On the Resource groups blade, find and then select the Serverless resource group that you created earlier in this lab.
-
On the Serverless blade, select the funclogic[yourname]** function app that you created earlier in this lab.
-
On the Function Apps blade, select the Functions and click on plus sign (+ Add) next to top.
-
In the New Function perform the following actions:
-
In the list of templates, select HTTP trigger.
-
In the New Function pop-up window, find the Name text box, and then enter Echo.
-
In the New Function pop-up window, find the Authorization level list, and then select Anonymous.
-
In the New Function pop-up window, select Create.
-
-
When the function is created click on Code + Test on left.
-
In the function editor, find the example index.js function script:
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
const name = (req.query.name || (req.body && req.body.name));
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
}
-
Delete all the example code.
-
Add the following lines of code to the function app:
module.exports = async function (context, req) {
context.log('Received a request');
context.res = {
body: req.body
};
}
-
Select Save to save the script.
-
The function should simply return what you send like echo.
-
Select Logs.
-
Observe the compilation results. The results should include a "Compilation succeeded" message.
-
Select Run to test the function.
-
Observe the results of the test run. The results should echo the original request body exactly.
-
In the Azure portal's navigation pane, select the Resource groups link.
-
On the Resource groups blade, find and then select the Serverless resource group that you created earlier in this lab.
-
On the Serverless blade, select the funclogic[yourname]** function app that you created earlier in this lab.
-
On the Function Apps blade, copy the value of the URL text box. You'll use this value later in the lab.
-
On the taskbar, select the Windows Terminal icon.
-
At the open command prompt, enter the following command, and then select Enter to start the httprepl tool setting the base Uniform Resource Identifier (URI) to the value of the URL that you copied earlier in this lab.
You can download and install tool by run command: dotnet tool install -g Microsoft.dotnet-httprepl
httprepl <function-app-url>
Note: For example, if your URL is https://funclogicstudent.azurewebsites.net, your command would be httprepl https://funclogicstudent.azurewebsites.net.
-
At the tool prompt, enter the following command, and then select Enter to browse to the relative api directory:
cd api
-
Enter the following command, and then select Enter to browse to the relative echo directory:
cd echo
-
Enter the following command, and then select Enter to run the post command sending in an HTTP request body set to a numeric value of 3 by using the --content option:
post --content 3
-
Enter the following command, and then select Enter to run the post command sending in an HTTP request body set to a numeric value of 5 by using the --content option:
post --content 5
-
Enter the following command, and then select Enter to run the post command sending in an HTTP request body set to a string value of Hello by using the --content option:
post --content "Hello"
-
Enter the following command, and then select Enter to run the post command sending in an HTTP request body set to a JavaScript Object Notation (JSON) value of {"msg": "Successful"} by using the --content option:
post --content "{"msg": "Successful"}"
-
Enter the following command, and then select Enter to exit the httprepl application:
exit
-
Close the currently running Windows Terminal application.
-
Return to the browser window with the Azure portal.
In this exercise, you created a basic function that echoes the content sent via an HTTP POST request.
-
In the Azure portal's navigation pane, select the Resource groups link.
-
On the Resource groups blade, find and then select the Serverless resource group that you created earlier in this lab.
-
On the Serverless blade, select the funclogic[yourname]** function app that you created earlier in this lab.
-
On the Function Apps blade, select the Functions and click on plus sign (+ Add) next to top.
-
In the New Function form, perform the following actions:
-
In the list of templates, select Timer trigger.
-
In the New Function pop-up window, find the Name text box, and then enter Recurring.
-
In the New Function pop-up window, find the Schedule text box, and then enter 0 * * * * *.
-
In the New Function pop-up window, select Create.
-
-
In the function editor, select Save to persist the default function implementation.
-
Select Logs.
-
Observe the function run that occurs about every minute. Each function run should render a simple message to the log.
-
Back on the Function Apps blade, perform the following actions:
-
Expand the node for the funclogic[yourname]** function app that you created earlier in this lab.
-
Expand the Functions node.
-
Expand the Recurring node for that specific function.
-
Select the Integrate node.
-
-
In the Integrate section, perform the following actions:
-
Select the Timer (myTimer) option in the Trigger section.
-
In the Schedule text box, enter the value */30 * * * * *.
-
Select Save.
-
-
Back on the Function Apps blade, perform the following actions:
-
Expand the node for the funclogic[yourname]** function app that you created earlier in this lab.
-
Expand the Functions node.
-
Select the Recurring node for that specific function.
-
-
In the function editor, select Logs.
-
Observe the function run that now occurs about every 30 seconds. Each function run should render a simple message to the log.
In this exercise, you created a function that runs automatically based on a fixed schedule.
-
In the Azure portal's navigation pane, select the Resource groups link.
-
On the Resource groups blade, find and then select the Serverless resource group that you created earlier in this lab.
-
On the Serverless blade, select the funclogic[yourname]** function app that you created earlier in this lab.
-
On the Function Apps blade, select the plus sign (+) next to the Functions drop-down list.
-
In the New Azure Function quickstart, perform the following actions:
-
In the list of templates, select HTTP trigger.
-
In the New Function pop-up window, find the Name text box, and then enter GetSettingInfo.
-
In the New Function pop-up window, find the Authorization level list, and then select Anonymous.
-
In the New Function pop-up window, select Create.
-
-
In the Azure portal's navigation pane, select the Resource groups link.
-
On the Resource groups blade, find and then select the Serverless resource group that you created earlier in this lab.
-
On the Serverless blade, select the funcstor[yourname]* storage account that you created earlier in this lab.
-
On the Storage account blade, select the Containers link in the Blob service section.
-
In the Containers section, select + Container.
-
In the New container pop-up window, perform the following actions:
-
In the Name text box, enter content.
-
In the Public access level drop-down list, select Private (no anonymous access).
-
Select OK.
-
-
Back in the Containers section, select the recently created content container.
-
On the Container blade, select Upload.
-
In the Upload blob window, perform the following actions:
-
In the Files section, select the Folder icon.
-
In the File Explorer window, browse to \Allfiles\Labs\02\Starter, select the settings.json file, and then select Open.
-
Ensure that the Overwrite if files already exist check box is selected, and then select Upload.
Note: Wait for the blob to upload before you continue with this lab.
-
-
In the Azure portal's navigation pane, select the Resource groups link.
-
On the Resource groups blade, find and then select the Serverless resource group that you created earlier in this lab.
-
On the Serverless blade, select the funclogic[yourname]** function app that you created earlier in this lab.
-
On the Function Apps blade, perform the following actions:
-
Expand the node for the funclogic[yourname]** function app that you created earlier in this lab.
-
Expand the Functions node.
-
Expand the GetSettingInfo node for that specific function.
-
Select the Integrate node.
-
-
In the Integrate section, perform the following actions to create a new input of type Azure Blob Storage:
-
Select Add Input.
-
Select Azure Blob Storage.
-
In the Blob parameter name text box, enter the value json.
-
In the Path text box, enter the value content/settings.json.
-
In the Storage account connection list , select AzureWebJobsStorage.
-
Select Save.
-
-
Back in the Integrate section, select the existing HTTP trigger.
-
In the HTTP trigger section, perform the following actions:
-
In the Allowed HTTP methods list, select Selected methods.
-
In the Request parameter name text box, enter the value request.
-
In the Selected HTTP methods check box group, ensure that only the GET option is selected.
-
Select Save.
-
-
On the Function Apps blade, perform the following actions:
-
Expand the node for the funclogic[yourname]** function app that you created earlier in this lab.
-
Expand the Functions node.
-
Select the GetSettingInfo node for that specific function.
-
-
In the function editor, find the example index.js function script:
-
Delete all the example code.
-
Add the following lines of code:
module.exports = async function (context, req, json) { context.res = { body: json }; }
-
Select Save to save the script.
-
On the taskbar, select the Windows Terminal icon.
-
At the open command prompt, enter the following command, and then select Enter to start the httprepl tool setting the base URI to the value of the URL that you copied earlier in this lab.
httprepl <function-app-url>
Note: For example, if your URL is https://funclogicstudent.azurewebsites.net, your command would be httprepl https://funclogicstudent.azurewebsites.net.
-
At the tool prompt, enter the following command, and then select Enter to browse to the relative api endpoint:
cd api
-
Enter the following command, and then select Enter to browse to the relative getsettinginfo endpoint:
cd getsettinginfo
-
Enter the following command, and then select Enter to run the get command for the current endpoint:
get
-
Observe the JSON content of the response from the function app, which should now include:
{ "version": "0.2.4", "root": "/usr/libexec/mews_principal/", "device": { "id": "21e46d2b2b926cba031a23c6919" }, "notifications": { "email": "[email protected]", "phone": "751.757.2014 x4151" } }
-
Enter the following command, and then select Enter to exit the httprepl application:
exit
-
Close the currently running Windows Terminal application.
-
Return to the browser window with the Azure portal.
In this exercise, you created a function that returns the content of a JSON file in Storage.
-
In the Azure portal's navigation pane, select the Cloud Shell icon to open a new shell instance.
Note: The Cloud Shell icon is represented by a greater than sign (>) and underscore character (_).
-
If this is your first time opening Cloud Shell using your subscription, you can use the Welcome to Azure Cloud Shell Wizard to configure Cloud Shell for first-time usage. Perform the following actions in the wizard:
- A dialog box prompts you to create a new storage account to begin using the shell. Accept the default settings, and then select Create storage.
Note: Wait for Cloud Shell to finish its initial setup procedures before moving forward with the lab. If you don't notice Cloud Shell configuration options, this is most likely because you're using an existing subscription with this course's labs. The labs are written with the presumption that you're using a new subscription.
-
At the command prompt, enter the following command, and then select Enter to delete the Serverless resource group:
az group delete --name Serverless --no-wait --yes
-
Close the Cloud Shell pane in the portal.
-
the currently running Microsoft Edge application.
In this exercise, you cleaned up your subscription by removing the resource group that was used in this lab.