Building serverless cloud applications using Azure Functions


>>Hey everyone. I’m Jeff Hollan, I’m a Senior Program Manager
inside of Microsoft Azure, and I’m excited today to
talk to you about building serverless cloud applications
with Azure Functions. There’s a lot of
great content here. We’re going to talk
about Azure Functions, what they are, how
they can be used. We will walk you
through a few demos to get you up and running
building your first, or maybe your 50th
serverless application. So, let’s go ahead and
jump right into it. So, the first thing
that we’re going to talk about are Azure Functions; what are they, why
do we have them, and how can we use them? So, the first part if you’ve noticed from the
Azure Function logo, these are actually
the two elements of it that I’m showing here
on the presentation. You have your code
that you write. Then there’s some events or data that are going to
trigger the use of that code. When that event
combines with the code, that’s where you have
here Azure Functions. It’s a relatively newer
service provided inside of Microsoft Azure that
allows you to build, publish, and deploy
cloud scale applications in a fraction of the time. So, you write your code in C#, in JavaScript, F#, or Java. More languages are becoming
available all of the time. You just published
that code to the cloud and everything else
is managed for you. So, this enables
you to not have to worry about things like scale or worry about things like utilization and
billing utilization. You just simply write your code and publish
it to the cloud, triggered on something
like an HTTP request, trigger when data is changed inside of
something like Cosmos DB, and everything else is managed
automatically for you. Another powerful capability
of Azure Functions that we’ll show you as we
go throughout the session, is that it can easily
connect to and integrate with other
services as well. Oftentimes you’ll
hear of a service like Azure Functions
being used as cloud glue as it stitches elements of
your application together. You’ve got a database over here, you’ve got a mobile
application over there, maybe you have some
analytics that run here. Azure Functions works great inside of those
individual components, stitching them together, and
integrating them seamlessly. So, I mentioned the language
support before, I wanted to go a little bit
deeper into that. If you’re interested
in writing in Azure Function, how
can you write it? So, today you can write it in C#, we allow you to do
either a C# script file or a full rich C# class
library application. You can write in JavaScript. We have a few different versions
of the Node runtime that will execute that
JavaScript on F#. And we have Java right
now that’s in preview. So, if you want to
write an application in Java using Maven tooling, in IntelliJ or VS
Code or Eclipse, that’s supported
today in preview. There’s a number of
other experimental languages; Python, Bash, PowerShell. And many of those
languages will actually continue to mature and evolve, and a few of them will eventually reach general
availability status. So, this gives you
a lot of flexibility. As a developer you can use the same platform,
the same tools, but choose the
language that’s best suited for both your experience, and the problem that
you’re aiming to solve. So, to start with, I know we’ve just started, we’re going to go into
a demo very quickly. Because I think it
helps to actually see what is an Azure Function, how do you build them,
what do they look like. So, I’m showing
here on my screen. This is the Microsoft
Azure portal, and if you want to
build an Azure Function it’s very easy to get started. You can actually
just come up here to the new “Start” menu, and actually just right
here in that first section, there is an opportunity to build a Serverless Function App. So, you can go ahead and
click that inside of Azure, and it’s just going to ask you a few details about the app
that you want to build; things like the name
of the app which will eventually become
the URL as you can see. You’ve got to choose a
subscription and a resource group, and a few of these other
options like “Hosting Plan” or “Application Insights” we’ll get into in a little bit. For now, you can just name this whatever you wanted
and create it. It just takes
a few seconds to create. I’ve actually created
one ahead of time. But this is what an Azure
Function App looks like. So, an Azure Function App
can be one or many individual functions
and I can manage all of the pieces I might
need to hear inside of the portal like creating
Azure Functions, managing insights on
them, or settings. Let’s go ahead and
create one now. So, I’ve just got
this blank function. I’m going to create a new
function inside of the app, and I can choose the scenario that I’m interested for now. Let’s actually show you all
of the different templates. So, here’s a few
getting started ones, but if I actually come over
here to “Custom Function”, you’ll notice here we have a bunch of different templates to
help you get started, whether you want to work
with Cosmos DB or IoT or WebHooks, GitHub,
scheduling email. All of these templates to help you get started
very quickly. I think a nice hello
world one though is just an HTTP trigger, a function that we
want to execute whenever we send in
HTTP request to it. So, let’s go ahead and choose C#, and I’ll just leave this as the default name and we’ll
go ahead and create it. Now, just in that little
amount of time here, what’s floating now on
my screen is my Azure Function. I’ll go ahead and zoom in here so you can read
it a little bit more. It’s not super important
what it’s doing, but needless to say, and
it’s about 20 lines of code, what will happen is when I send an HTTP request to this endpoint, it’s going to go ahead
and run this code for me. Now, in this case, what the code is
actually doing is it’s looking to see if
I’ve provided a name, and I could provide
that name either in a query parameter of the URL, or in the actual body of
the URL and the content. If I provide a name, it’s
going to go ahead and return back a hello message, okay? So, here’s the code. I could continue to edit it and write here if I wanted to, but for now let’s go ahead
and just test this out. For now my name is not Azure. I’ll go ahead and
change my name to Jeff. Here if I might need to zoom out a little bit to see
this test button down here, we’ll save and run. Let’s go ahead and run
this function now. And so here in the cloud, it just executed
this little bit of code, and you’ll see here
down at the bottom I see my message, hello Jeff. So, I don’t have to
worry about how this is hosting all of the pieces
running behind the scenes. I just simply write
that little bit of code or logic that I want
to execute on demand. Here’s that URL for me that
I can call at any time now to execute that code,
and I’m up and running. So, this is super convenient
as I need to write different pieces of
functionality to run on demand. Maybe I’m writing a website
or a back-end API. Maybe I want this
to run on a timer. Instead of me having to
write boilerplate code or figure out anything else, I just write this simple bit
of code like I’ve showed you here inside of the Azure portal. The one last thing I want
to show you too is well, during this demos that
I can continue to connect and integrate this
with different elements. So maybe instead of just
returning back a hello message, maybe I actually want to emit something to an Azure event hub, or add an entry into
Azure Cosmos DB. And I can configure
and set all of that up here directly within
the Azure portal as well, and make it so that
my code runs on-demand, talking to the services
that I needed to talk to. So, what this is is that this
is completely serverless. Which means that if
you execute this, will spin it up on demand for you and you’re only ever
charged for what you use. So this type of a programming
model is extremely useful, and I actually want
to talk about some of the customer success stories that we’ve seen in
Azure functions. Azure Functions as I
mentioned is relatively new, but there’s a number of large corporations
and enterprises, or even startups
that are using this today and finding
immense value from it. One that I want to talk
about briefly is Fujifilm. They’ve got this popular
image work service that they began to leverage serverless functions to improve their application. So, as they started to solve different technical
challenges for their image work service
and use Azure Functions, they found that their latency
went down as they were able to run on demand
for the triggers, for the events that
they care about. The big item here
that I hear time and time again is actually
the second bullet point, that development time is incredibly reduced
with Azure Functions. In this case they
state 75 percent. I hear those kind of numbers
all of the time, right? They used to take us six months to build
the feature end to end, now we can do it in
just two months or in one month, because we’re no longer worried about what operating system
is this running on. How do we scale up?
How do we scale down? You just simply write the code for the function
that you care about. They get massive
reliability because Microsoft Azure is managing the infrastructure
behind the scenes. And if they need to add new features or
create new releases, they’re able to
effectively do that. So, that’s just one
example of a customer who’s found success in
this serviceless function model. We’ve got dozens more, if you actually go to the
customers.microsoft.com page, you can see about a dozen
of these published used cases for customers who found incredible value
from functions today. So, it’s something
that we want everybody to be able to find value for. And one of the reasons it’s very exciting and I have
alluded to this already, is that it is built on this
serverless application model. So, let’s talk about
what serverless is and to set the context for this. If you think about
the evolution of applications. So, if 20 years ago
you were tasked to build some web application
or some callable endpoint, you would have likely
had to build that on-premises or maybe
with core location, but you’d have to go
provision all the hardware, purchase a bunch of hardware, build a bunch of machines
or racks of servers, install operating
systems on them, get them patched and upgraded. Make sure that you have
enough hardware, right? If I’m building a web application
for an e-commerce site, do I need one server? Do I need 100 servers? And that’s a lot of money. Like I have to invest
a lot of money and time before I even
touch the code. So, I’m spending a bunch of time and resources and cycles, I’m planning I’m
provisioning I’m building, before I ever actually even
build the application code. And as you look at
the evolution as we go forward, a few years later we introduced infrastructure
as a service. This is the first and
the starting of cloud. We’re now instead of you
having to go build the server, now you can just go to a cloud provider like
Microsoft Azure and say, hey, I want a virtual machine. I want it to have 500 gigabytes of hard drive space and
seven gigabytes of RAM, and two core processor, and maybe I want 20 of them. And you say that and those are
already ready for you now. But as a developer, I still
have to go in and configure, and manage, make sure that my virtual machines
are secured, that they’re up to date. So even though I can
get them faster, I’m still spending
a lot of cycles on maintaining these servers
and managing them. Further up the evolution, you get the beginnings of
platform as a service. This now enables you to say, hey, I don’t want to worry
about the operating system under the scenes as much. I don’t want to
have to worry about how many of these things I need. I just want a website. So I’m going to give
you my website code, and the rest is
taking care for you. Things like Azure App Services is a great example of
a platform as a service, where you want to
publish a website, you just give the website code. And this is great, but I still do have to make
a selection of size, when I create one
of these things. Like I have to choose, do I want a small app service plan or do I want a large app service plan? Do I need 20 instances or
I’m okay with just one? And you have control over
things like autoscaling, but still I’m taking a lot
of my time managing and planning and conforming
my application to how it’s hosted. So, this final tier here, the one on the far right
is serverless. And this is what
Azure Functions is, there’s a few other services in Azure that conform to this. But what this enables me to do is now I simply write the code. All I have to do is
write that little bit of code like I showed you, and everything else
is manage for me. So, as a developer, this is fantastic because
I’m no longer worried about all of those
different other pieces that I’d normally
be worried about, whether it’s capacity
and all of those pieces. So, what is severless?
Really is its core. There’s kind of three tiers
that we talked about, the’re three pillars that
we emphasize heavily. The first is you get
an abstraction of servers. So, when you built that Azure function the one I just
showed you a moment ago, I wasn’t worried
about what size of virtual machine is running
behind the scenes, I just wrote
my little bit of code. And the service manages, and we’ll put this on whatever
servers that I might need. It’s event driven, right? We have to spin up the resources to execute your code on demand, which means that
Microsoft Azure needs some event to trigger off of, to let us know, hey, run this little bit of code. And the example I
built just a few minutes ago that was
an HTTP request. Somebody sent a web request, that event would drive
us to execute the code. The event could be
something like at five o’clock on
a Friday afternoon, run this little bit of code, or whenever a tweet
happens in Twitter, run this little bit of code, or a commit happens in GitHub, run this little bit of code. So, events can be very flexible. These can be business events
like the purchases made, or technical events like
an entry is added to a database. But these events are what
attached to your code, to let your code know to execute and what data
to execute on. And the final aspect of
serverless is micro-billing. You only are charged for when your code
is actually running. So, if your code never runs, you don’t see any bill. The next day your code
runs a million times, you only pay for
the amount of time that your million of events
are actually executing. So this means that
now as a developer, as a business owner, you don’t have to
worry so much about how many of these
virtual machines do we need, and how do we make sure
that we’re not losing profit if we have
a slow sales day. That doesn’t become
a factor anymore. You just say, when
an order happens charge the credit card and send
them a confirmation email, and if one person makes an order, or if one million person
makes an order, your application just works and you only pay for
what you’re using. So, the benefits here are a little bit more clear based
on what we’ve talked about, but the first one is that
now is the developer, now is a business you’re
managing apps not servers. All of that time that
you’re traditionally spending, managing
that infrastructure, dealing with the scale
of that infrastructure, dealing with their reliability is now taking care of for you, so that you can focus
on the applications. This translates to
reduced DevOps, right? Now, when I’m developing or
operating these applications, I’m spending less of
that time focusing. This is part of why
companies like Fujifilm see that 75 percent reduction in time to market their features, because so much has shaved off, being taken care of by
the platform itself. And last but not least, and we just alluded
to this as well, this all translates to
faster time to market. This enables you as a business, as a developer to build and ship applications in
a fraction of the time. So if we look at
serverless in Azure, I mentioned that there’s
actually a few pieces here. This is a little bit
of a map of what serverless looks like
inside of Microsoft Azure. The first part here, we’ll, actually start on
the right side of this chart is Azure Functions. This is that serverless compute, that serverless code
that you execute. The one I just built
a little bit ago is 20 lines, have C sharp code that
returned back a hello message, okay? That’s Azure functions. Azure Logic Apps isn’t code, you’re actually building
business workflows or development workflows to
orchestrate different calls. So maybe if an order is placed, you’re going to
charge a credit card, and then inventory
needs to get notified, and then you need
to send an email, and then you need to
create a shipping notice. There’s multiple different steps in this process to happen, and logic apps is
a serverless tool in Azure that enables you
to define those events. It will coordinate
the execution of all of those different steps, but it also gives you over 200
connectors out of the box. So, if you need to integrate
with a service like say Pay.On premises or Salesforce
or Dynamics or Google Docs, there’s just connectors to enable you to do that right
out of the box. And finally in the serverless
spaces event grid, we’re not going to go super
into event grid today, but this enables you
to route events to different serverless components
of your application. There’s actually another session as part of this tech summit, which goes over
the serverless platform and into each of
these individually, we’re going to focus
today just on functions. But it is important to know that this entire platform is built
on a rich set of databases, IoT technology,
intelligence services. So, all of these different
powerful components in the cloud are
at your disposal. And you get rich development
tooling as well. We showed the portal
development experience but we’re going to go
through Visual Studio. You could use Visual Studio code, you could use IntelliJ, or Eclipse, or Java functions, get real time local
debugging and development, which is a unique offering
that Azure provides. So, one of the other cool parts of Azure Functions is
that it’s actually very flexible in the different ways that you can run
your Azure Functions. So, I’ve talked a lot about
the server list model, but there are some scenarios where you actually might want more flexibility in how your function is actually
hosted and running. So, I’m going to break
some of those down. So, the first one
that we’ll call out is this consumption model. That is the one where you’re only paying for
what you’re using, that scale is all dynamic that
we can scale down to zero, or we can scale up to thousands of executions, millions
of executions. It’s all happening for you, and you’re only being paid
for what’s being executed. But sometimes you
might actually want to host functions in
a different way. In other ways that you
can actually deploy functions into an existing
App Service Plan, or into a new App Service Plan. We often call this a dedicated
hosting model because now instead of spending
up resources on demand, you have a dedicated set
of instances that have your Azure Functions running on them all of the time. Now, why might you want
the App Service Plan? Often we’ll see people use
the App Service Plan if they want to have functions that
run for a very long time. Maybe an hour, two hours, three hours for
a single execution. Serverless functions
are be running all of the time in that they’re
always listening for events, but a single execution
like a single HDP request, that code can only be running
for up to 10 minutes. If you have dedicated resources, if there are servers there 24/7, well now you have a little bit more flexibility
in how long your code runs, in where your code
runs, and so forth. The next one is
an App Service Environment. This takes it to
the next stage where now instead of just having
dedicated resources, you actually have
an entire isolated environment. This enables you to do
things like ExpressRoute, or VNet Integration for rich
on-premises connectivity. You get perfect consistency
in how everything executes. So, that’s another option if you’re already using
an App Service Environment, or you want things running
in an isolated environment, you can take
that same function code, and just deploy it over to
an App Service Environment. You can also run Azure
Functions on the Azure Stack. So, if you have Azure
On-Premises in Azure Stack, you can run those same functions
on-premises as well. And we also have what’s called the Azure Functions Runtime. This is a runtime that
you can install on a Windows server so that it maybe you don’t have
the full Azure Stack, you just have
a server, and you want to execute these functions, that’s totally fine as well. And the last one is
pretty exciting. This is the Azure IoT Edge. So, if you have an Edge device, maybe you have something
like a parking garage, and you have cars
coming in and out, and there’s a little bit
of code that needs to run whenever a car enters
your parking garage, that same flexible
programming model that I used moments ago
in the Azure portal, I could deploy that same type of functionality to
Azure IoT devices, or even span a number of these different
hosting models so that my function code
is running exactly where that function code
will be most optimal. So, we talked about
the consumption plan. If you’re building
a new function, you’ll see here this is
that new Azure Function menu. You can choose consumption
plan right there. You’re only paying for
what you’re using. We’re assigning compute resources on-demand, and dynamically. So, we will see what
your application is asking for, and make sure that
there are servers ready to run your code on-demand. You can be running tons of stuff in parallel on a function. So, you don’t have
to worry about, ”What if I have
a thousand people who all have this function
at the same time?” We’ll scale up, and
manage that all for you, so you don’t have to
worry about that, and execute them in parallel, so they happen quickly as well. You only pay for what
you’re executing. And again, this is
a great option if you want that elastic scale, if you might be scaling
from zero to massive. If there’s going to be gaps
into when you’re executions are happening because you’re only paying for what you use. Now, if you select
that App Service Plan, I talked about this
before as well, but now you have dedicated virtual machines
just like websites, basic, standard, premium,
one instance, 20 instances. And this will always
run your code, whether it’s being
executed or not. So, this is good if you maybe already have
an App Service Plan. Maybe you are already hosting a website on an App Service Plan, and you can see from your
metrics that you’re only using 80 percent of
that App Service Plan. So you’ve got 20 percent
of spare compute there. Or you could run
these Azure Functions for free in that 20 percent compute, just by deploying
those functions into that plan. I also mentioned this as well, this is also a great option
if you have a function that’s running constantly,
or almost constantly. Maybe listening to
something like a WebSocket, and you need to be
constantly polling, or constantly listening to that WebSocket, and
publishing events. We’ve talked a lot about functions I
showed you on briefly, but there are
a few concepts that are unique to Azure Functions that are important
to call out here. So, functions is
the unit of work here. So, I have a problem, the function is the unit
of work of how I solve it. And all functions are executed, they start, and they finish. That’s just some
terminology here. So, my function execution starts, it runs its code, and when
it’s finished, it completes. Functions trigger off of events. And those events are called the trigger in
the Azure Functions. So, when you build
Azure Functions, when you’re developing
Azure Functions, you will be selecting
the trigger. You’ll choose, ”What’s
the trigger I want to have?” And I sh owed you this as
well in the Azure portal, you might also have
inputs and outputs, you might get an HTP request, but want to pull in
some data from Cosmos DBM, maybe write some data to Azure storage as a result
of that function. Or you can have those inputs,
and those outputs. They can even be dynamic. And then the functions
programming model, we call those bindings. So, these are inputs or outputs that bind
to your function. So, you have your trigger
that starts your function, and then you have bindings
that can help enrich the data, or maybe push data out
to different sources. So, here’s an example. This is a JavaScript function
in this case. Well, you’ll notice this
is the single execution. This is the single
function I mean. And it will have
an execution that starts. It’s going to just run
this little bit of code. In this case it’s
actually pulling messages to Event Hub,
or from Event Hub. I actually be this is an input binding from Event Hub,
or a trigger. And it’s going to go
ahead and process them, and then complete. And here’s another example, this is C# in this case. And in this case I’m
actually using C# attributes to annotate my function code, but
you’ll notice here, I’m actually triggering
from a queue message, I’m going to go ahead and
read in some Blob data, and I’m actually going to
write out some Blob data. So, I have an input binding, and an output binding. And then I have
my little bit of code here. Those bindings are
super useful too because you’ll notice
here in the C# example, I’m talking with
Azure Storage Queues. I’m also talking with Blob, but the actual code of
my function is a single line. Just copy the data from the file name to
the other file name. So, all of the integration code, all of the code to talk to Azure Blobs is taking
care of it for me. I just write
this little bit of code, and it runs on demand. Tons is managed by
the platform itself. Now a very common
scenario that we see with Azure Functions are
building Serverless APIs. Similar to the one I built today. You call this over HTTP
and you get a response. Maybe you have a mobile app
and you do call things from your mobile app and
you need APIs exposed. So one of the awesome offerings that Azure Functions provides, is a solution to this problem. So, let’s say you have
a mobile application and you have three individual pieces of functionality that you have. You’ve got some
customers functionality, you have some product
functionality and you have some
order functionality. Now, I can write these as
three individual code bases. And I can even publish them as three individual functions to manage them independently.
This is great. This allows me to maybe version the customers API without having to touch the products API. But one of the problems
that comes from this, is you’ll notice I
actually now have three distinct surfaces, customers.azurewebsite, product.azurewebsite,
and order.azurewebsite. And this now means that something like my mobile application needs to be aware of and call
each of those individually. And if I go and change
my customers API, I might actually
have to go update the code of
my mobile application. That’s a little too tightly coupled for
a number of people. So, what we actually provide
here in Azure Functions, are what are called API proxies or Azure
Functions proxies. And in this case, you can
actually have a single surface. You’ll see here I
have my customers API but I actually have a proxy to my products and to my orders API that’s being managed for me. So, in this case, here, I have a single endpoint which
exposes both my customers, my products and my orders. But they can route to those individual
function code bases. So, now I still have
flexibility that I can go version my product API,
I can go change it, add it whatever, and now
I just have to update that proxy and
my mobile application can still call
that same endpoint. I just have one URL, one API path and I
can start to build these very rich API trees, have a single surface but call multiple different Azure
Functions behind the scene. So this is a really
powerful model. This is totally
Serverless as well. We see people doing
a similar model with something like
Azure API management, which provides even richer security and monitoring
and user access control. Now the proxy is phenomenal for building fully
Serverless APIs as well. So I wanted to call
that out here. Tooling. This is actually a really an area of a lot of strength
for Azure Functions. Is the number of tools that
you can build these functions in and how you can
build those together. So, I showed you
the Azure portal. That’s very quick and easy to get something
up and running, especially if you’re doing “Hello World” you’re just
getting your feet wet. But often times you just start to build more
complex application, you’ll want to start using
a full code editor or IDE. So we do have first class
integration with Visual Studio and Visual Studio 2017 in the Cloud workload. There is an Azure
Functions project, which I’ll show you
in just a minute. You can code these in
Visual Studio code. There’s an Azure Functions
Visual Studio code extension to write C#, Java or JavaScript functions. And we have an Azure
Functions CLI. So that if you want to write your own deployment
scripts or even write these with whatever
editor you want, you can use the CLI which
works cross-platform. On Mac, on Linux, on Windows to build and deploy these Azure Functions or test them with any of these solutions. So, when we think about
development Toolings there’s kind of this inner loop
and the outer loop, right? The inner loop is building it and the outer loop is managing them. Okay. So, when we look at the Azure Functions
development tools the inner loop and
the outer loop, the local debugging
and the local testing, all runs inside a Visual Studio, Visual Studio code or the CLI. And you can publish from
a number of different tools too. So I could publish
directly from any of those development tools
that I talked about. We also have integration
with systems like Visual Studio Team Services,
Maven, Jenkins. So whatever you might
be publishing from, you can publish with
an Azure Functions. For monitoring, like something
is now published now. You need to monitor
it or version it, there’s a native integration with Azure application insights. So that you can query the
traces of your function both your own personal
application logs or system logs to
get an insight into, how is my function running? How long is an execution taking? How many executions happened? What about exceptions. That’s all built for you inside
of application insights. And there’s also integrations
with continuous delivery. So one of the cool
functionality pieces from Azure Functions is that you can check your code into
something like GitHub, Visual Studio Team Services
or Bitbucket and have those automatically be deployed
to your Azure Function. So, now when you go check
in an update to GitHub, that update will
automatically go and roll out to your different functions
that are deployed. And you can continue to evolve
this with services like Visual Studio Team Services
for a full CICD pipeline. So, there’s a lot of
flexibility for you there. Now let’s go ahead
and do another demo quickly and I want
to show you some of the development
Tooling available for you in Azure Functions. And in this case, I’m actually here
inside a Visual Studio. Now, this is Visual Studio 2017. I actually have
this project right here, so I’m going to go ahead and set this Azure Functions product right here as my startup project. I’ll show you how I got here, if I’m in Visual
Studio I just say, “I want a new project.” And right here in that Cloud
workload as I mentioned, you can create
Azure Functions all within Visual Studio 2017. So, I have one here ahead of time that I’ve just
done that step. It’s an empty project
at this point. So now I want to start adding functions to it so that
I can deploy them. So, I can go ahead and just add a new Azure Function
to this project. And I can give this
any name I want. And in this case,
the scenario I actually want, is I have an IoT device
that is submitting a bunch of data into
an Event Hub or into an IoT Hub. And I want to read that data. So I’m just going to
call this my IoT reader, I will go ahead and add it. And you’ll notice here
I have a bunch of different triggers
that I can listen to for IoT or Event Hubs. I’m just going to
say, “Hey, this is the trigger that I want to have.” It’s going to be a new message
in my Event Hub. Now here it’s asking me, what’s the connection
to your Event Hub? And I’ve actually configured
this ahead of time, but I have a connection called Event Hub Connection String which I’ll show you where
that’s stored in just a second. And I have an Event Hub
that’s already deployed and it’s called
“My Events, Event Hub”. So I went into the Azure
portal ahead of time. I’ve created an Event Hub and
I have an Event Hub there called “Events” where
I’m going to listen to and this is
my connection string. So let’s go ahead and
click “Okay” here. And it’s going to spin up that Azure Functions template for me with a little bit of code. So here’s the start
of this function. You’ll notice this is
what I configured here. It’s an Event Hub trigger syncing to this thing
called the events. I have this connection called the “EventHubs
ConnectionString”. Now one important thing
to note when you’re using the Visual Studio
Tooling is that, these different settings and connection strings are actually stored inside of
your local settings file. So, I’ve opened my
local.setting.Jason file, and here is where I have defined the
“EventHubsConnectionString”. And I’ve set this as
an application setting here. Okay. And when I publish
this I also have my application settings
in the cloud, so maybe I have
a different Event Hub that I work with locally and when I publish I have a different one in the Cloud or different
environmental variables. So I can manage all of
those here as well, all within Visual Studio. Now one cool thing here. All I’m going to do
here and this code is, we’ll get the Event Hub message, and we’ll just go
ahead and log it. So, let’s say, “Hey, I got
an Event Hub message.” I can actually do something like set a breakpoint right here in Visual Studio and
click the “Run” button. Now it’s exciting here
inside a Visual Studio. You’ll notice we are
actually spinning up right here on my machine, the Azure Functions runtime. So this is the exact same runtime that will be running
inside of the Cloud, and you’ll notice here
that I’ve actually picked up a message from my Event Hub. So I’d sent a message to “My
Event Hub” ahead of time, it went ahead and picked that up. It hit my breakpoint. You’ll notice here I can
see my Event Hub message. It’s this Jason object which is being stringified
in this case, and it’s going ahead and I could step through
this and debug this as I might need to make sure that everything is how I
want it to perform. So all here in
Visual Studio I get local debugging
connected to the Cloud. Notice here it says, “Hey, I got your log message.” So now it’s logging
that log message, it was from device A and
it said message, “Hello.” So in just a few clicks, I’m able to start
building my function. I could continue to write
more code here as I needed. Save it, debug it, run it, all here within
Visual Studio 2017. And when I’m ready to publish it, I can just right
click and publish to publish to a function App in the Cloud ready for me to go. Okay. So very nice integrated Tooling all within Visual Studio to get me up and running. IntelliSense, debugging, all
of the pieces that you’re familiar with as a developer
inside a Visual Studio. The same kind of
dev workflow works as well for Visual Studio code. If you’re developing
on Mac or Linux or Windows if that’s
your choice as well. All right. So let’s go ahead here and talk about monitoring. So, I built a simple
function app that’s listening to Event Hubs
data in this case. How do I make sure that
my app is performing well? This is something
you’ll hear often in the serverless space is monitoring is
something very tricky, you might have a number
of applications. How do you make sure
that they’re healthy? How do you understand
how they’re performing? How do you get alerts if
something is unhealthy? What if I have a function
that’s now just throwing exception after exception
after exception? How do I make sure
that I’m making improvements that
we’re progressing in the right direction
if I am hitting bugs? How do I learn how my application is performing
and make changes to it? These are all challenges not just unique to
serverless functions but that are a kind of
in their infancy in the industry
across server lists. But it is not
that case with Azure. In Azure, we actually
have rich integration with Azure Application Insights. So, if you recall
back when I went to that first create blade when I created my first Azure Function, it actually asked
me, “Do you want to turn on Azure
application insights?” The answer is you do,
because it’s going to give you answers to all those
questions I asked ahead of time. So, Azure Application
Insights gives you an extensible application performance
management platform. Now, what does extensible mean? Well, this means that you can admit your own custom events from your own custom sources to
enrich the data as well. So, we’ll emit all of your logs and the systems data
from your function. But if you want to
send custom tracers or custom telemetry, you’re totally welcome do so with Azure
Application Insights, so you won’t hit a ceiling there. This gives you really rich data. You get metrics,
how many executions that I have, you get traces so you can look into log data as your debugging, exceptions are tracked for you so if your code ever
throws an exception, you can just query
that directly and understand what’s
the inner exception, what’s the outer exception. You can even chart dependencies. You can say, “Oh
this function app is dependent on storage or this function app
is dependent on SQL.” View things like
page views, requestoration, custom event, all of that
is provided out of the box. You don’t have to
set any of that up. You really just turn
on that hey turn on app insights and
all of this stuff just gets submitted
for you automatically. Another powerful piece
is that you get nice graphs and
charts and analytics, they can even integrate
with services like Power BI so that you can visualize and get alerts on how your
application is performing. And again, this is all just
natively handled inside of Azure Application Insights
with Azure Functions. So, I want to show you
what that looks like now. So, I’m going to come
back here, this is my screen and this is that same IoT application that we published a
second ago to Azure. But what I’m actually going
to do here is I want to now publish a bunch of events to it and lets
monitor this thing. Let’s see how it performs. So, I’m going to go
ahead and switch over to this second project I have
here and the solution. In here, I’m going to
send 30,000 events. I’m going to simulate
30,000 IoT devices, all sending events in parallel to the same Azure Function that
I just deployed, right? So I ran it locally once. I haven’t done anything
but publish the thing, I haven’t dealt with scaling. Now, let’s run this thing 30,000 times and see what happens. So, I’ll go ahead and
run the simulation now. It’s going to go ahead
and simulate those 30,000 IoT devices getting
pushed in parallel, you’ll see it’s sending
those messages now. I’m going to switch over here now to Azure Application Insights. Now, this is actually
the live view. This is a live Metric stream that you can listen to
and you’ll see here, here’s my different traces. You’ll notice here’s those logs that we have being emitted. I have all of those 30,000
events that are getting pushed in and I can see
exactly how they’re coming in. So, you’ll notice here at least based on how it’s
ramping up right now, I’m getting about a thousand
requests per second, a single instance is only executing for about
a second or less. And what’s great down here
is I can actually see my Azure Function is scaling. You might not have
just caught it but I used to only have
one server here and now I have three and this might
even continue to scale up as IoT devices keep sending
events at such a high rate. But I can even understand
how my application is being utilized across
all these different IoT devices. So, I did nothing but write
that simple log file, went through the template
connected it to my Event Hub, but now I have scaled across three full powered Azure servers and I’m monitoring them live. I see exactly I’ve got three full servers running and
processing events. It looks like it just
jumped up to four. So, now you have four servers right and this
will continue to scale as it needs to make sure that my requestoration
stays really low, to make sure that I’m
handling the load. And this is all real
live monitoring that I have a handle on. So, that was that live stream
that I had access to. I could come in here as well
and I can start to explore the metrics or even do analytics on top of
this application as well. So, I’ll just show you
that briefly as well. I’m going to go ahead
and open the analytics for this IoT application we just built and here’s an example of some of the different
data sources, right? If I want to look at any
exceptions that are happening or the requests that
are coming in or traces as they’re occurring, you remember I’m emitting
some trace logs. So, let’s go ahead and just look at what these traces are. I’ll go ahead and click
run here and here and all the traces from
my function application. In this case, I’ve got a timer trigger here that’s running. I’ve also got
my Event Hubs trigger, my IoT reader as
the one we call it. All of those traces are all here. I can query them. I can write some filtering
syntax, some summary syntax. It’s all just provided
for me out of the box. So, that was a quick example
of how not only does my function App scale
but also get real time analytics and
monitoring on top of it. Okay, so I do want to
as I kind of wrap up here talk about
how Azure Functions is an open source project. You can watch us develop
in the open on GitHub. We have a number of different
repositories here as well. There’s the SDK script, the extensions, the binding, the CLI, the portal, template samples, all
of it’s in the open. We love contribution from contributors and we get
contributions all of the time and you
can also watch us track issues and start
to work on them as well. So, if you are interested
in contributing or at least just following
along in our development, be sure to check out on GitHub some of
those repositories. Okay, so some final
thoughts here. Thank you so much
for sticking with us and hopefully this
has been helpful for you to give you a feel
for what Azure Functions are, how they can be built, how they can be monitored, and how they can scale. First and foremost if you have not built Azure Functions before, try Azure Functions,
try to build one. See how it runs, see
how it executes. Azure Functions is
a robust and mature service. It’s generally available we have thousands and thousands of customers running millions
of executions every day. You can follow along with us
on Twitter @AzureFunctions. A number of the team myself included are on Twitter as well always contributing and asking and answering questions
from our users. We’ve got a few
samples that you can deploy into your own
subscription yourself. There’s one where
you get a website that allows you to
do a tug of war. We have one that creates
a photo mosaic for you. Try them out. We’ve got tons of documentation on
docs.microsoft.com, samples, quick starts. Get started. Let us know if you
have any questions. We’re more than happy to help. So, thank you all very much for joining today and let us know
if you have any questions. And good luck and have fun
using Azure Functions.

Leave a Reply

Your email address will not be published. Required fields are marked *