Introduction to Microsoft Azure Serverless Cloud Computing
What is Cloud?
In simple words, Cloud Computing is the on-demand delivery of IT resources via the internet. Instead of buying maintaining and accessing the on-premises servers and data centers, one can access the technology services such as computing power databases and storage services.
Certain services and models are working behind the scene making cloud computing feasible and accessible to end-users, following are the working models for cloud computing.
- Deployment Models
- Service Models
There are three Deployment models
- Public Cloud
- Private Cloud
- Hybrid Cloud
A public cloud is an IT model where on-demand computing services and infrastructure are managed by a third-party provider and shared with multiple organizations using the public Internet.
A private cloud is a cloud computing environment that is exclusively dedicated to a single entity or a service. It runs on the organization’s premises or in an external data center. It is managed by the organization’s operations team or a managed service provider.
Hybrid cloud is a mix between private and public server, that’s mean if you have an application hosted in public and private cloud called Hybrid cloud.
Service Models are referenced models on which Cloud Computing is based.
There are three Cloud Service Models
- Infrastructure as a Service(IaaS)
- Platform as a Service(PaaS)
- Software as a Service(SaaS)
Infrastructure as a Service(IaaS)
In Infrastructure as a Service, you rent IT infrastructure, including Virtual Machine, Storage resource, network, and operating system.
Platform as a Service(PaaS)
Platform as a Service refers to Cloud computing services that provide an on-demand environment for deploying, testing, and delivering software application services.
Software as a Service(SaaS)
Using software as a service is different, there is no server, no user interface. What you get is software.
Functions as a Service(FaaS) or Serverless Cloud Computing
Serverless or functions as a Service (FaaS) means that the developer is more focused on the application at the task level than the server level. You don’t need to worry about the operating system or under-going infrastructure on Serverless.
What is Microsoft Azure
Microsoft Azure is a cloud computing platform created by Microsoft which developers and IT professionals use to build, deploy and manage applications through their global network of datacenters.
The Hallmarks of Azure Serverless consists of Trigger/Events, Orchestration, and Compute. Let's discuss them one by one.
Orchestration defines the workflow for the serverless function. For this, we have Logic Apps and Durable Functions. Azure Logic Apps is a cloud platform for automating workflows that integrate apps, data, services, and systems using little to no code While Durable Functions is a code-based development where you define stateful workflows by writing orchestrator functions and stateful entities by writing entity functions using the Azure Functions programming model.
There are three types of trigger/Events
- Time — Scheduling an event to perform a task at a specific date and time.
- External Event — change in the data can trigger this external event.
- State Change — changing in the state, for example, someone updating the shopping cart.
Most Common Capabilities in Serverless Cloud Computing
Most of the Serverless Services which are available on the public clouds are following.
- Health and Performance
- Logs and Diagnostics
- Access Management
- Activity Log
Introducing Microsoft Azure Functions
What is Microsoft Azure Functions
Functions are feature-packed FaaS offerings from Microsoft Azure that enables you to run your code directly on-demand in Azure’s infrastructure. Think of them as pieces of code that are invoked by triggers, wherein you do not have to worry about the underlying infrastructure.
You can choose any programming language of your choice from C#, F#, Node.js, Java, Python, PHP, etc., and bring in dependencies from NPM, NuGet, and Maven.
What is a function?
A function is a central concept in Azure Functions. You can write code for a function, in any language of your choice, and save the code and configuration files in the same folder. Azure Functions Runtime reads the configuration file to determine the events to be monitored and how to pass data into and return data from function execution.
What are bindings?
Bindings are ways to simplify coding for data input and output. Bindings are optional, and a function can have multiple input and output bindings.
Azure Functions integrate with most of the Azure services as well as some of the third-party services. These integrations can behave as triggers as well as bindings for your function.
Azure Functions Pricing
There are two Pricing plans followed in the Azure Functions which are the Consumptions Plan and Premium Plan. On the Consumption plan, instances of the Functions host will be dynamically added and removed based on the number of incoming events. Consumption plans are great for testing and development. While in Premium plan applications can run with no delay, run on more powerful instances and connect to VNETs. You can switch from Consumption to Premium plan anytime so the recommendation is to start with consumption plan first.
Creating Azure Functions Using Azure Portal
Creating Azure Functions from Azure Portal is Simple, First, you need to login into your Azure account, and then from the Search bar, search for the Functions App.
Once clicked, it will redirect you to Functions App Page, on the top left you will see a Create Button, click on it and it will pop up the azure functions creation page, fill in the details and then review and create button.
Once it created all the services which are required for the Azure Functions like storage, you can access the functions, Monitoring, Metrics, Access Management, Health, and Logs of the functions.
Creating and Deploying Azure Functions Locally Using SDK
Now, We created the Function App, so create Functions, we need to do it locally using VSCode. Please make sure the following tools are installed in your local system before we get started.
- Node CLI
- Python CLI
- Git CLI
- Functions Extension in VSCode
After the installation creates a new project and then Go to the Functions Extension which we installed recently in the VSCode.
Click on Sign-In to Azure, once you sign in to your Azure portal, it will display the Function App which we created earlier, Now we need to create a function for this you can click on the Create Function button,
and after this, it will ask you different details like which language interpreter, compiler detail, and choose the HTTP Trigger, and then choose the Anonymous, so it can be easily accessed from the internet.
Now we need to install azure core tools, for this, you can use the following command, please make sure you are doing this on CMD, because on Windows sometimes Powershell producer errors.
npm install -g azure-functions-core-tools@3 --unsafe-perm true
To start the function, you can use the following command
it will launch the localhost, from where you can run the trigger. it will look something like -> localhost:7071/api/HttpTrigger1 , so in this simple code you need to pass a name, for this, you can simply do this
and it will print out Adil's name in the function. Once everything seems ok, we can deploy this function to the Azure portal.
So, if we go back to the Azure Portal and then to the Functions app, we can see an HTTPTrigger in the functions.
Click on the HttpTrigger1 and then click on the, Click on the Get Function URL.
Deploying Azure Functions using GitHub Actions CI/CD
Now let's do Continuous Integration and Continuous Deployment of this function using GitHub Actions. For this first, we need to deploy our Project to GitHub Repository, Use these Git commands one by one.
git add .
git commit -m “first commit”
git branch -M main
git remote add origin <YOUR GITHUB REPO URL>
git push -u origin main
Now let's go back to the Azure portal and the Functions app, from the left menu select the Deployment Center and then Select GitHub for Continuous Integration and Deployment.
Now in the deployment center, connect your GitHub account and then provide the repository name and the branch, so you can do CI/CD using Github actions.
Once you save it will create a .github/workflow/.yaml file to your Github repository. In your Local repository, you need to fetch and pull to get the latest commits from the Github repository.
git fetch --all
Now, let's make changes to the code, and then again you need to add and commit to the local repository and then you can push using the push origin command. You can add a new code or make changes to the sample code, it's up to you right now I want these things simple for you. after pushing the latest changes it will start the Github action workflow for us.
CI depends on Continuous deployment because if CI failed then it will not deploy CD to Microsoft Azure. Now let's check our changes on the Microsoft Azure function which we created naming HTTPTrigger1.
Technical case Studies
Most of the Microsoft Azure functions case studies on the official website from where you can easily learn the use cases which are grabbed by different organizations around the globe and how they implement the azure functions in their applications.
In this blog, we learn what is Cloud Computing, we cover Serverless types and their key features, and we also do how we can crate function app, how to create functions using VSCode and then we learn how to deploy CI/CD GitHub actions and integrate the latest changes easily with the help of Git, GitHub and GitHub Actions on Microsoft Azure.