Part 4: Creating a function and creating a HTTP trigger

Part 4: Creating a function and creating a HTTP trigger

Creating an Azure Function?

Search for Function in Azure.??

Click + Create?

Hosting option: Consumption?

Click Select?

Subscription: Choose your subscription?

Resource Group: rg-hrarchiving (For me it’s rg-hrarchiving-2)?

Function App name: fahrarchiving (For me it’s fahrarchiving-2)?

Runtime stack: Python?

Version: 3.11 (Current version as the time of writing this)?

Region: The one closest to you?

Storage tab:?

Storage account: sahrarachiveblob (v2)?

Click Next.?

Network tab: Leave the default.?

Monitoring:??

Enable Application Insights: No ?

Review + Create, Create?

Installing Python?

We are going to use VS Code and Python to configure our Function. Before we jump into the code, there are a few prerequisites we need to download and install:?

  • Python?

  • Node.js?

  • VS Code extension: Azure Functions?

Installing Python is the first step in setting up the Function, so let's start with that.?

Search for Python online and download version 3.11.?

Run the installer and make sure to check the boxes at the bottom of the installer window:?

Once installation is complete, click "Close."?

Next, open PowerShell with administrative privileges and run the following command:?

Set-ExecutionPolicy RemoteSigned?        

Note: This command allows you to run local scripts, which is necessary since, by default, script execution is restricted to prevent potentially harmful scripts. You can revert to the default setting by changing it back to Restricted after you finish testing. For more details, consult the Set-ExecutionPolicy help notes when you are ready to go live.?

Installing Node.js?

Next, search for and install Node.js. On the Node.js website, download and install the prebuilt installer. During the installation process, accept the default settings and make sure to uncheck the box if it’s selected.?

Installing VS Code packages?

Now, open VS Code, navigate to the Extensions tab on the left sidebar, and search for "Azure Functions." Click "Install" to add the extension.?

Creating HTTP Trigger?

Once installed, you should see an Azure icon at the bottom of the left panel VS Code. We’ll use this icon to create the Function Project.?

?Click on the A.?

The Azure Functions tab in VS Code has two sections: the upper and lower sections.?

  • The upper section connects to your Azure profile, enabling you to deploy the project.?

  • The lower section is used to create the Function project locally.?

?

Click on Create Function Project.?

A window will open where you can select a directory for your Azure projects. You can create a new project folder and choose it from this window. For example, I created a folder named Azure HR Archiving.?

?

?

After creating and selecting your folder, click "Select."?

For this project, we will be using Python for the development.?

?

Select Model V2?

?

?

Click py 3.11.9?

?

?

Click HTTP Trigger because we are going to perform a POST in ADF?

Give it a name: http_trigger_post_blob_index?

Choose Function?

?

?

Open in current window?

Click Trust the Authors of your new folder?

You should now see a new list of files that make up your Function project:?

?

Click on function_app.py

When you create a Function project, a template code is automatically set up for you, and it works as a basic starting point. We’ll be removing most of this template code and replacing it with our own.?

Next, we need to install the azure-functions-core-tools in VS Code. This tool enables local development, testing, debugging, and deployment of Azure Functions directly from the editor.?

In the terminal tab at the bottom of VS Code, type the following command:?

npm install -g azure-functions-core-tools?

?

After the installation is complete, you should be able to debug your project without errors. If you encounter any errors in the debug output, look them up and resolve them as needed.?

In Part 5, we'll set up Postman to send a message to the API.

Go back to Part 3

要查看或添加评论,请登录

社区洞察

其他会员也浏览了