Azure Functions

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
14 hours 28 minutes
Difficulty
Intermediate
CEU/CPE
15
Video Transcription
00:00
>> Hello Cybrarian. Welcome to lesson 7.1 of Module 7 of
00:00
this course titled AZ-301
00:00
: Microsoft Azure Architect Design.
00:00
Here are the learning objectives for this video.
00:00
We'll start out by discussing Azure Function,
00:00
and I'm just introducing
00:00
you to what an Azure Function App is.
00:00
Then proceeds to cover
00:00
the core features of Azure Functions.
00:00
Then we'll go ahead and cover
00:00
the runtime versions that exist for Azure Functions.
00:00
There are three main runtime versions,
00:00
but we'll cover the differences between
00:00
them and most importantly,
00:00
which one you should be
00:00
using when designing the solution.
00:00
We'll then cover the different hosting plan options
00:00
that are available for Azure Functions which
00:00
determines how you're going to
00:00
pay for Azure Functions and
00:00
also has a big impact on
00:00
your architecture in terms of scalability.
00:00
Then we'll cover how Azure Function works and
00:00
go into a bit more details regarding the service.
00:00
We'll then conclude by talking about
00:00
Azure Function from a cost perspective.
00:00
Let's get right into this.
00:00
Let's start out by understanding
00:00
what Azure Function app is.
00:00
Azure Function app is a service in Azure for running
00:00
small pieces of code in the Cloud. What does that mean?
00:00
What that means is that rather than
00:00
focusing on a whole application,
00:00
we can break down the application into
00:00
smaller logic sets and implement
00:00
the smaller logic sets as
00:00
microservices running in Azure Functions.
00:00
It fits very well into a microservices architecture.
00:00
One of the other things to know about
00:00
Azure Function app is
00:00
that it is an extension of the Azure App Service.
00:00
All the feature sets that applies to
00:00
Azure App Service also applies to Azure Function app.
00:00
In terms of some of the other core features
00:00
of Azure Functions,
00:00
it supports multiple languages from C-Sharp,
00:00
all the way to scripting languages like PowerShell.
00:00
In terms of pricing options,
00:00
there are different options that we
00:00
have on how we pay for Azure Functions.
00:00
We can either pay on something
00:00
called consumption-based versus dynamic
00:00
or pay-as-you-go or we can pay for dedicated resources.
00:00
We can have dedicated or
00:00
reserved resources available for
00:00
our function have to run up.
00:00
Also when it comes to the services
00:00
I mentioned this earlier,
00:00
Azure Functions is an extension of Azure App Service,
00:00
which means that features like Azure AD,
00:00
integration for easy half
00:00
also works with Azure Functions.
00:00
It has natively built-in integrations
00:00
with services in Azure like Cosmos DB,
00:00
Even Hub, and Notifications Hub,
00:00
which means you can read data very easily with from
00:00
the services or you can use them as
00:00
triggers for your Azure Functions.
00:00
There is that native integration that's built in,
00:00
also for services like
00:00
GitHub and even services like Service Bus.
00:00
Azure Functions has three versions of the runtime.
00:00
Now out of this three versions of the runtime,
00:00
only two are currently GA,
00:00
and that's generally available and
00:00
that's version 1 and version 2.
00:00
One of the other things to notice that
00:00
only GA releases are supported for production,
00:00
which means even though you are seeing version 3 on
00:00
the slide right there,
00:00
it's not something that you want to use in production.
00:00
One of the other things to mention is
00:00
that vision 1 is currently in maintenance mode,
00:00
so announcement are provided only in later versions,
00:00
and the word version 2 and version 3.
00:00
Also try to stay away from version one,
00:00
if you can, and just use version 2 mainly.
00:00
When we create a Function App in Azure,
00:00
one of the things that we have to choose
00:00
is the hosting plan for our app.
00:00
We have three hosting plans that are available.
00:00
We have the consumption plan.
00:00
The consumption plan,
00:00
the main case about this is that the app can
00:00
scale up and scale down
00:00
>> based on the loads that come in,
00:00
>> not something that we need to configure,
00:00
not something that we need to predetermine is
00:00
set of resources that will be available to our app.
00:00
We simply say as a code to run and as
00:00
much compute power as that code
00:00
needs to run based on the loads that's coming in,
00:00
make that available to the code.
00:00
That's the consumption plan.
00:00
Then we have the premium plan.
00:00
The premium plan has
00:00
some key functionality that doesn't exist in the others.
00:00
Number 1 is something called pre want instances.
00:00
Now with Azure Function,
00:00
like let's say the consumption plan,
00:00
if there are no events or execution of the code,
00:00
the app can scale down to zero instances.
00:00
What that means is that all of a
00:00
sudden if there's a new trigger,
00:00
it takes time to implement
00:00
the backend infrastructure that will run
00:00
the code and to warm it up.
00:00
That can lead to a delay.
00:00
What premium plan allows us to say
00:00
>> is to be able to find a certain number of instances
00:00
>> that we always stay warm so that our code,
00:00
>> whenever it's triggered, can
00:00
execute as quickly as possible.
00:00
That's one of the advantages of using
00:00
>> this premium plan.
00:00
>> One of the other advantages that it has,
00:00
they support virtual network connectivity
00:00
using service endpoints.
00:00
Then we have the dedicated plan.
00:00
The dedicated plan is where we're taking
00:00
our Azure Functions and we're
00:00
running it in an Azure App Service plan.
00:00
An Azure App Service plan
00:00
>> is where we pre-define a set of
00:00
>> resources and the number of resources
00:00
that our backend can scale to.
00:00
We pre-define that ahead of time.
00:00
Just be aware that if you're using
00:00
>> the App Service plan,
00:00
>> it requires that Always On is enabled.
00:00
Let's have a look at how Azure Function works.
00:00
The first constructs that we need to
00:00
implement Azure Functions is we need a function app.
00:00
The function app is what hosts our code.
00:00
Our code runs within a function app,
00:00
and our code is also referred to as functions.
00:00
We can have multiple functions
00:00
running within a function app.
00:00
In order for our code to run,
00:00
it needs to be triggered.
00:00
What are the options that we have when
00:00
it comes to triggers?
00:00
Some of the options you can see on the left-hand side.
00:00
For example, we can trigger
00:00
the execution of a code that's
00:00
hosted within an Azure Function app
00:00
based on an event grid subscription,
00:00
which I'll show you that in the demo,
00:00
based on data being added to Cosmos DB collection,
00:00
based on Event Hub,
00:00
based on HTTP tree guys,
00:00
one of the common ones,
00:00
or even based on the schedule.
00:00
You can say this code executes based on
00:00
this schedules frequency, based on service.
00:00
Those are some of the triggers
00:00
that we have on the left-hand side.
00:00
Also, within our code,
00:00
there may be instances where we need to pull in
00:00
certain information maybe from another service.
00:00
Those are called input bindings in Azure Functions.
00:00
Input binding is a way to supply data or integrate with
00:00
a service and be able to supply data right
00:00
into our code or inject that data into our code.
00:00
In terms of input bindings,
00:00
Azure Function has multiple options
00:00
of what we can implement.
00:00
For example, we have the Blob Storage, Cosmos DB,
00:00
Graph API, Signal R,
00:00
Table Storage, and multiple others.
00:00
We can only have one trigger,
00:00
but we can have multiple input bindings.
00:00
For example, in the case that I have on the screen,
00:00
the trigger objects triggers
00:00
the execution of the code
00:00
and then the code begins to execute.
00:00
Now within that code, we make a call to the input
00:00
binding to grab some data from Cosmos DB,
00:00
and then we pull in that data and
00:00
then another part of our code
00:00
maybe does some processing on that data.
00:00
We use the input bindings for that.
00:00
But we can have multiple input bindings,
00:00
but only one trigger.
00:00
Also, we may want to output the data or
00:00
the information to somewhere else.
00:00
That's called output binding
00:00
or output binding in Azure Functions.
00:00
Now, with output bindings,
00:00
there are multiple bindings that are available also.
00:00
Here are just some that I'm listing on the screen.
00:00
This is not by any means an exhaustive list,
00:00
just to give you an idea.
00:00
For example, we could now take that information of
00:00
the the output of our code and
00:00
then puts that into Cosmos DB somewhere,
00:00
put that into a queue or pass that into Event Hub,
00:00
or just put that into Blob Storage.
00:00
Let's look at the HTTP trigger for a minute.
00:00
With the HTTP trigger,
00:00
which is very common,
00:00
it's as simple as making an HTTP request to
00:00
a URL that's generated whenever we create a function,
00:00
and that's how you trigger the function to execute.
00:00
But we can also control what's allowed and what's not
00:00
allowed or in what way can
00:00
our function be triggered using the HTTP.
00:00
For example, we can define the methods that
00:00
are acceptable or the method that's allowed.
00:00
We can choose get only
00:00
accepted if what we want
00:00
is a function that only accept request,
00:00
but does not allow any rights.
00:00
Or we can choose to allow posts,
00:00
or the other HTTP methods that we
00:00
can choose to allow or not allow.
00:00
We can also define the authorization level
00:00
>> that we want.
00:00
>> Anonymous level means anyone that has the URL
00:00
can make a request and trigger the function to execute.
00:00
Function level means that
00:00
the function key will be
00:00
required before you can trigger this function.
00:00
Whenever you create a function,
00:00
it generates an API key.
00:00
Then the API key,
00:00
you need to supply that within your HTTP header
00:00
before you can trigger the function if you're
00:00
using function level authorization.
00:00
If you're using admin or system level authorization,
00:00
what that means is,
00:00
for the function app itself that
00:00
can contain multiple function, it has a key.
00:00
Anyone that has the key to
00:00
that function app itself can trigger
00:00
any of the other functions within that function app.
00:00
That's what the admin and system levels is referring to.
00:00
But we have control over
00:00
that is what I want to get across to you.
00:00
Let's look at some of
00:00
the design decisions of Azure Functions.
00:00
Let's look at costs.
00:00
When it comes to costs,
00:00
we mentioned earlier that we have
00:00
the consumption model or we have
00:00
the Azure App Service plan,
00:00
or we have the premium plan.
00:00
When it comes to the consumption model,
00:00
which is one of the most popular options,
00:00
billing is based on the number of executions,
00:00
the execution time, and the memory use.
00:00
That's what we pay for.
00:00
You say for example,
00:00
if you have a function that consumes
00:00
about 0.5 gigs of RAM,
00:00
and that function runs for three seconds,
00:00
then the execution cost will be
00:00
0.5 gigabyte of RAM that the function uses
00:00
times the amount of time that
00:00
a function is executing for and that
00:00
is what will be equals to 1.5 gigabyte per second,
00:00
and that's what we pay for.
00:00
What that means is that a function that runs
00:00
for longer costs more.
00:00
If your function is busy loading
00:00
all these dependencies and doing all this other stuff,
00:00
it's going to cost you more in terms of
00:00
execution because you're paying as you go.
00:00
Also a function that consumes
00:00
more memory also is going to cost more.
00:00
Be aware of those.
00:00
Now, when it comes to billing,
00:00
billing is aggregated across
00:00
all function within a function app.
00:00
We're going to pay for it at the function app level,
00:00
and it's going to charge for how the functions
00:00
that are running within the function app.
00:00
There's a free grant that's
00:00
included on a per subscription basis.
00:00
I'm highlight here there's
00:00
a free grant of 400,000 gigabytes per
00:00
second that's free in
00:00
terms of memory and in terms of execution.
00:00
The first million executions are free.
00:00
But be aware that this free grant
00:00
is only per subscription basis,
00:00
not on a per function basis.
00:00
Also, there's no downside or impacts to having
00:00
multiple applications running in
00:00
the same consumption plan.
00:00
If you're worried about would this
00:00
affect performance on some of the other stuff?
00:00
There's no downside and impact
00:00
if you have multiple functions
00:00
running within a single function app.
00:00
Still talking about costs.
00:00
Whenever we're using Azure Functions,
00:00
there are other costs that we have to be aware
00:00
of beyond just the function app itself.
00:00
For example, we cannot create
00:00
an Azure Function app without a storage account,
00:00
and that storage account to be built
00:00
also for the billions of storage account.
00:00
It's also a good practice to have application insights,
00:00
which will be able to give us more telemetry as to
00:00
the monitoring of our Azure Function,
00:00
and that also has its own costs.
00:00
Of course we pay network bandwidth for data that's
00:00
transferred outside of the region or outside of Azure,
00:00
there is a cost to that.
00:00
Data that's been transferred within
00:00
the same region is not charged for.
00:00
Maybe that's going to affect how
00:00
you architect your solutions.
00:00
This brings me to the end of this lesson.
00:00
Thanks very much for watching,
00:00
and I'll see you in the next lesson.
Up Next