Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Sameer Jejurkar
Sameer Jejurkar

Posted on • Originally published atblog.cloudbuff.in on

Deploying our first function to Azure

In theprevious article, we created a simple function with HTTP trigger and tested it locally. Now it's time to deploy it to Azure cloud platform.

Create an Azure account

Before we can deploy our first function to Azure, we will need an Azure account. For this, we will go the toAzure website and sign up for a free account. Note that you will have to provide credit card information and some additional information depending on your location. Usually, Microsoft provides up to US$ 200 worth of Azure credit when you sign up.

Create a Resource Group

Once you are logged into Azure, the first step is to create a Resource Group. This is simply a logical container for keeping related cloud resources together. Go to the search bar at the top and typeresource groups. Click onResource groups in the Services section of the results.

01_portal_search_rg.png

Our subscription should automatically be selected on the creation form. Let's specifyblog-functions-rg as the name of the resource group and select a region. You can select any region you like. For e.g., you can choose the region your located in or a region close to you. We will go withEast US.02_portal_create_rg.png

Click onReview + create to proceed. If everything is good, a "Validation Passed" message will be displayed.03_portal_create_rg_valid.png

Clicking onCreate will create the Resource Group.

04_portal_rg_details.png

Create a Function App

Now, let's create a Function App. TypeFunction App in the search field at the top and click onFunction App in the Services section of the results.

05_portal_create_rg_fn.png

Again, our subscription will be automatically selected. We will use theblog-functions-rg Resource Group we just created and name our Function Appblog-function-app. Note that this name must be globally unique because Azure uses<function-name>.azurewebsites.net as the base URL for the Function App. So, you will have to choose a different name. We are going to deploy the function we created using Visual Studio Code, so we will chooseCode as the Publish option. We will pick.NET as the Runtime stack and6 as the version since that is what we used to create our function. We will select the same region as the Resource Group,East US, to deploy the Function App.06_portal_create_fn_app.png

We will use Linux as the Operating System (Windows will work too, but we will go with Linux as it appears to be the more popular choice for deploying code in the cloud). There are several pricing plans available and we will look at all the available plans in more detail in a future article. For now, we will go with theConsumption plan as this is a true serverless plan. You are charged based on how many times the function is executed. Another nice thing with this plan is that first 1,000,000 executions are free.07_portal_create_fn_app_2.png

Click onReview + create to proceed. A confirmation screen will be displayed. ClickCreate to create the Function App.

09_portal_final_create_fn_app.png

It may take some time for the deployment to be completed. Once it is complete, we will see a confirmation. Click onGo to resource to view details.

10_portal_fn_app_confirm.png

Click on theFunctions menu on the left. Currently, there are no functions under this Function App.

12_portal_fn_app_functions.png

Create a Storage account

We must link a general purpose Azure Storage account to the Function App we just created because it relies on Azure Storage for operations like managing triggers and logging function executions. Since we don't have a Storage account, we will create one. In Azure Portal, typestorage in the search bar and click onStorage accounts in the Service section of the search results.

20_portal_storage_1.png

We will choose the sameblog-functions-rg Resource Group. We will useblogfunctionstorage as the name (note that we cannot use hyphen, underscore or any other special characters in the name). We will select the same region as the Resource Group,East US. We will go withStandard option for Performance, since it will work for most scenarios and low latency is not really a requirement for us. ForRedundancy we will opt forLocally-redundant storage (LRS) as it is the lowest cost option and recommended for non-critical scenarios. For production environments, it is advisable to useZone-redundant,Geo-redundant orGeo-zone-redundant option depending on your requirements and budget. ClickReview button to proceed.20_portal_storage_2.png

ClickCreate to create the Storage Account.20_portal_storage_3.png

Once the Storage account is created, we should see the details in the Portal.20_portal_storage_4.png

Link the Storage account to Function App

Now let's link this Storage account to our Function App. For this, we first need to get the connection string for our Storage account. Click onAccess keys item in the left menu. That will display Access keys for the account. Click on the copy icon at the end ofConnection string field.20_portal_storage_5_keys.png

Go to the Function App by searching forFunction App in the menu. Click on the name of the Function App.21_portal_fn_navigate_00.png

Select theConfiguration item from left menu. Under theApplication Settings tab, click on+ New application setting link.21_portal_fn_config.png

OnAdd/Edit application setting pop-up form enterAzureWebJobsStorage as the name and paste the Storage account connection string that we copied earlier. Click OK.

21_portal_fn_config_WebJobsStorage.png

After the pop-up form closes, click on Save icon to save the new setting. We have now linked our Storage account with our Function App.21_portal_fn_config_save.png

Deploy function

Now, we will switch over to Visual Studio Code, open the project that we createdpreviously and deploy our function. Click on the Azure icon in the left menu.

13_VSCode_Azure_login.png

Click onSign in to Azure... option. This will open a browser window. Login with your Azure credentials.

14_MS_sign_in.png

Upon successful login, we should seeSelect Subscriptions... option in VS Code. Let's select our subscription from the drop list.15_VSCode_Azure_subsription.png

Open the Command Palette using keyboard shortcutCtrl + Shift + P (useCmd + Shift + P on Mac) orView > Command Palette... menu option. TypeAzure Functions: Deploy into text box and selectAzure Functions: Deploy to Function App... option.16_VSCode_deploy_function.png

A list of Function Apps defined in Azure will be displayed. As we have created only one Function Appblog-function-app, we should see just that in the list.17_VSCode_deploy_select_fapp.png

When we selectblog-function-app for deployment, there will be a warning saying the previous deployment will be overwritten. We will clickDeploy to proceed.

18_VSCode_deploy_fapp_warn.png

A Terminal window should open in VS Code and we should soon seeDeployment to "blog-function-app" completed. message pop-up.

18-2_VSCode_deploy_fapp_done.png

Our function code has been deployed successfully. If we go back to Function App in Azure Portal and click onFunctions menu item, we should seeSimpleHttpFunction in the list.

21_portal_fn_view_deployed.png

Now that our function is deployed, let make sure it works. Open a new browser or tab, put URLhttps://blog-function-app.azurewebsites.net/api/SimpleHttpFunction into the address bar and press enter. If a message like the one below is displayed, it means our function was executed successfully.22_browser_invoke_1.png

Now let's modify the URL. Add aname query parameter withJack as the value:https://blog-function-app.azurewebsites.net/api/SimpleHttpFunction?name=JackWe will get a different response now. As you can see that both responses match what we saw when we tested the function locally.22_browser_invoke_2.png

And that's it!! We have successfully deployed our function to Azure.

Conclusion

In this article, we deployed a simple function with HTTP trigger to Azure cloud. In the next article, we will create a function that gets triggered when a message arrives in a Storage Queue.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Solutions Architect || Cloud Architect || AWS Certified
  • Joined

More fromSameer Jejurkar

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp