Table of Contents
What is Serverless?
Serverless computing (or serverless for short), is an execution model where the cloud provider (AWS, Azure, or Google Cloud) is responsible for executing a piece of code by dynamically allocating the resources. And only charging for the number of resources used to run the code. The code is typically run inside stateless containers that can be triggered by a variety of events including http requests, database events, queuing services, monitoring alerts, file uploads, scheduled events (cron jobs), etc. The code that is sent to the cloud provider for execution is usually in the form of a function.
- Azure Subscription
- Azure Function Deployed in Subscription
- Visual studio installed
Step 01: - How to create Azure Function in subscription
To create a function app, visit https://portal.azure.com and log in to the portal using your credentials. Once your login is successful, you will get redirected to the Azure portal dashboard. Type function app in the search bar and click the Function App option.
Now click the Create button to create a new function app resource.
Then, Follow the wizard as per below image. Fill the details of below
- Subscription in which you want to get billed for this Azure function app.
- Resource Group where you need to create the function app
- Function App Name: - Name of your function app
- Publish: - You want it to be deployed as Code or as Docker Container.
- Runtime Stack: - We have multiple stack available .Net, Node.js, Python etc.
- Version and Region are available as per availability
Then click on Next : Hosting. Here you can select on which platform you want to deploy your app Like Windows or Linux. Also, you must select the Plan type.
Plan type is nothing but the different SKU available for your function app workload. We will go with azure Consumption plan as it almost fits in every situation and free for almost 1M execution.
Click Next: Monitoring and navigate to the Monitoring tab. It is highly recommended that you enable Application Insights for your Azure function app because it will help you to monitor and analyze Azure Functions. Click Yes to enable Application Insights and create a new insight.
Tags help you categorize Azure resources. You can add tags along with tag values for Azure resources and use the tags to classify a group of resources. Now click Next: Review + create
On the Review + Create tab, you will see a summary of the configurations you have selected for the function app. To create the function app, click Create. Your configuration inputs for the function app get validated. If there are no validation issues, then the function app creation will start.
Step 02: - Deploy function app using Azure Portal
After function app deployment we can see the below option in overview as per below image. You can click on browse option to see you function app.
- Browse: - it will redirect you to app URI
- Stop: - you can stop function app so it wont running in backend and will not accept request.
- Get Publish Profile: - it will download app configuration file.
- Download App Content: - you can download your code and configuration using this option.
Now let configure function app using Develop in Portal option. Click on create option and it will open the one window as per below image.
Here you can select trigger as per your need. Azure Function offer multiple types of triggers. Http Based triggers, Event Based, Blob Trigger etc.
For our demo we will use Http trigger and click on create. After creating you can see multiple options.
In Code + Test pane you can write your code and run in portal to validate.
Although, you can configure it in graphical way using integration tab. You can add input output using other azure services like Blob storage etc.
And finally, you can monitor your applications in Monitor tab it will create live stream logs to make debugging easy.
Step 03: - Create function app using Visual Studio
First open your visual studio on local machine and create new project. Also make sure you have downloaded azure components for your visual studio so you can find Azure functions template.
Create new project and search for azure function and click on next.
Give project name and location and other basic options. Once you have provided the necessary configuration information, click the Create button.
This opens the dialog used to select the type of Azure Function that you’re creating. Here you can get multiple option and triggers for this article will use Http trigger. Select None for storage account and click on next.
An Http trigger is fired when a request is received through the HTTP pipeline. This allows an Azure Function to be initiated using any technology capable of submitting an HTTP request, which, to be fair, is just about every technology.
After clicking on create you can see multiple files. These files contain your code here you can write your code build on local machine and then publish it to Azure Functions.
Right click on function file and you would see a multiple options like Build and Publish.
Build will compile your code and test it on local machine. And you can test you function app using function framework installed on machine.
Now, lets publish our using publish button as per above image. After clicking that you get options like Azure, Docker container etc. will go with Azure.
After that you have to select on which platform your app is running is it on Windows or Linux and select it accordingly.
Next step is to configure your azure storage account to deploy it there. Sign into the portal using your credentials.
Now , its just we are only two clicks away from publishing our app. Now it will check the configuration and setting and validate it.
Lets hit the Publish button and done. In same pane you can see the configuration and connection strings. So it will guide you to configure setting that needed.
Yes. It published successfully. Let’s go to portal and see our app which we deployed from local machine.
Yes, its they’re with the name we have given. The only drawback of using this method is we can not edit it through portal. You have to edit it from client.
Let’s see our application. You can test it using postman or you can integrate with your application.
Azure Function is a serverless compute service that enables user to run event-triggered code without having to provision or manage infrastructure. Being as a trigger-based service, it runs a script or piece of code in response to a variety of events.
Benefits of Azure Functions
- Choice of language – write functions using C#, F#, Node.js, Java, PHP, batch, bash, or any executable.
- Pay-per-use pricing model – pay only for the time spent running your code. See the Consumption hosting plan option in the pricing section.
- Bring your own dependencies – functions supports NuGet and NPM, so you can use your favorite libraries.
- Integrated security – protect HTTP-triggered functions with OAuth providers such as Azure Active Directory, Facebook, Google, Twitter, and Microsoft Account.
- Simplified integration – easily leverage Azure services and software-as-a-service (SaaS) offerings: SendGrid, Twilio
- Flexible development – code your functions right in the portal or set up continuous integration and deploy your code through GitHub, local Git, Visual Studio Team Services, and other supported development tools.