Azure Function Apps Tutorial | Introduction for serverless programming

Adam Marczak - Azure for Everyone
12 Aug 201929:18

Summary

TLDRThe script provides an introduction to Azure Function Apps, a service for running event-driven serverless code without managing infrastructure. It outlines key features like flexible development, multiple languages and runtimes, easy integration with Azure services via bindings, and a consumption-based pricing model. A demo walks through creating a blob triggered function that processes files uploaded to blob storage, highlighting simplified functionality with only a few lines of code. The video conveys how Function Apps enable rapid development and deployment of scalable, cost-effective solutions.

Takeaways

  • 😊 Functions are small pieces of reusable code that can be triggered by events
  • πŸ‘ Function pricing is cheap - first 400,000 GB-s and 1M executions are free
  • πŸ”₯ Bindings make connecting functions to other Azure services simple
  • πŸ“ Many languages are supported including C#, Java, JavaScript, PowerShell & Python
  • πŸš€ Quickly create functions in the Azure portal for testing before deploying from VS Code
  • πŸ”— Triggers start function execution and outputs enable writing results to services
  • πŸ“¦ Bindings support Azure services like Blob Storage, Event Hubs, Cosmos DB etc.
  • βš™οΈ The host.json file controls low-level settings like routes, concurrency limits etc.
  • πŸ›  Use App Settings to manage environment configurations and connections strings
  • πŸŽ‰ Functions scale automatically without managing servers, so no infra overhead!

Q & A

  • What are Azure Functions and what are they used for?

    -Azure Functions are a service for running small pieces of code without having to manage servers or infrastructure. They allow you to focus just on your code while Azure handles scaling and management behind the scenes. Functions are commonly used for data processing, integration, scheduled tasks, and more.

  • What languages and frameworks can you use to write Azure Functions?

    -You can write Azure Functions in C#, Java, JavaScript, PowerShell, Python, and more. On the .NET side, you can use both the .NET Framework and .NET Core.

  • How are Azure Functions triggered?

    -Azure Functions need to be triggered in order to execute. Triggers could include HTTP requests, changes in database data, queue messages, file uploads, scheduled timers, and more. A function can only have one trigger but may also bind to multiple inputs and outputs.

  • How are Azure Functions priced and scaled?

    -By default Azure Functions run on a consumption plan, which means you only pay for the resources used while your functions run. There is a free grant for the first 400,000 GBs processed and 1 million executions per month. Beyond that, pricing is very low cost per million executions and gigabytes processed.

  • Where can Azure Functions code and configuration be edited?

    -In the Azure portal, you can edit Function code and configuration directly. For more robust development, Azure Functions can be developed locally using Visual Studio Code and deployed to Azure. Configuration like bindings can be set both declaratively in code as well as visually in the Azure portal.

  • How does simplified integration work with Azure Functions?

    -Binding to inputs and outputs is very simple with Azure Functions. For example, you can bind to blob storage and automatically trigger when a new file is uploaded or bind to a database and query data within your function. These bindings require just a simple declarative configuration.

  • What is the purpose of the host.json file?

    -The host.json file controls settings for how the Azure Functions runtime should behave, including things like HTTP routes, concurrency limits, timeouts, and more. This allows control over the environment without having to manage VMs or infrastructure.

  • Can Azure Functions integrate with other Azure services?

    -Yes, Azure Functions have out-of-the-box integration with several Azure services via bindings, including Storage, Cosmos DB, Event Grid, and many more. This allows using other Azure services directly in your serverless functions.

  • What options exist for testing and monitoring Azure Functions?

    -The Azure portal provides built-in testing capabilities for Functions. Additional monitoring is available by integrating Application Insights, which will provide telemetry data on function executions. Functions can also be tested locally before deploying to Azure.

  • How are connections to other resources handled in Azure Functions?

    -Connections to linked resources like storage accounts are configured through application settings that are automatically supplied to the functions when running. For local development, these connections can leverage the local emulator.

Outlines

00:00

😊 Introducing Azure Function Apps

The paragraph introduces Azure Function Apps, explaining they allow running code without managing servers or infrastructure. It outlines key benefits like scalability, low cost, and ease of use across languages. A comparison to Azure App Service is made, noting functions extend its capabilities. Use cases and triggers are also discussed.

05:03

πŸ“ Function Apps Simplified Integrations

The paragraph discusses simplified integration in Function Apps. It explains triggers invoke functions, passing inputs and accepting outputs. Bindings to services like blob storage are easy, allowing combining triggers, multiple inputs and outputs across services in a few lines of code.

10:06

πŸ—ƒοΈ Function Apps Triggers and Bindings

The paragraph lists the extensive triggers and bindings available in Function Apps v2, including blob storage, databases, authentication providers, and more. It notes some like Event Grid can only be triggers while most can also be inputs/outputs. The flexibility to combine multiple services is emphasized.

15:10

✨ Creating a Function App in the Azure Portal

The paragraph steps through creating a function app in Azure Portal. It shows key steps like naming, OS, hosting plan, runtime stack selection and storage configuration. Application Insights is also provisioned for logging. Total deployment takes 2-3 minutes after which the function app user interface is explored.

20:11

πŸ–₯️ Developing a Function App with Visual Studio Code

The paragraph demonstrates developing a function app locally using Visual Studio Code instead of the portal. It steps through creating a blob trigger function app, configuring bindings, and deploying to Azure. Successful end-to-end functionality is confirmed by uploading a file to blob storage and verifying output file creation.

Mindmap

Keywords

πŸ’‘Serverless

Serverless computing refers to cloud services where the cloud provider manages the server infrastructure and automatically provisions resources as needed to run applications. This removes the need for the developer to provision or manage servers. The video explains that with serverless, you don't have to manage infrastructure underneath and can focus on just managing code.

πŸ’‘Function Apps

Function Apps is a Azure service that lets developers write event-driven snippets of code or 'functions' that run in the cloud. The video focuses specifically on Azure Function Apps which make it easy to connect functions to services like blob storage through bindings.

πŸ’‘Functions

Functions refer to the small reusable pieces of code that carry out specific tasks. The video explains that functions are triggered by an event, they accept input data, execute code to process that data, and return output data.

πŸ’‘Triggers

Triggers refer to the events that cause a function to execute. Common triggers include HTTP requests, changes to database data, messaging events, etc. The video explains that every function has a single trigger binding.

πŸ’‘Bindings

Bindings provide a declarative way to connect functions to services without having to write custom integration code. They handle connecting, sending, and receiving data. Besides the trigger binding, functions can have multiple input and output bindings.

πŸ’‘Blob Storage

Blob storage refers to a cloud storage service where files and large amounts of data, called Objects or BLOBs (Binary Large OBjects) can be stored flexibly. The video demonstrates a function triggered by a blob storage event, processing the blob data, and outputting it to another blob.

πŸ’‘Host.json

The host.json file controls the configuration for an entire function app including things like HTTP routes prefixes, concurrency limits etc. It is either part of the function codebase or configurable via the portal.

πŸ’‘HTTP Trigger

A HTTP trigger causes a function to execute whenever it receives a HTTP request. The video shows an HTTP function that takes the name parameter from the query string, processes it, and returns a dynamic response.

πŸ’‘Azure Storage Account

A storage account provides a unique namespace for Azure Storage data objects. The video configures local development to use the storage emulator while production connections use the Live Azure Storage Account specified in App Settings.

πŸ’‘Deployment

Deployment refers to publishing function code and configurations from the development environment to the hosting Azure environment. The video demonstrates deployment from Visual Studio Code to automatically override the function in Azure.

Highlights

Functions is a service for running small pieces of code, so you have that script in dotnet or maybe java or any other languages that is supported

You can pay per use so the price is super super cheap because first four hundred thousand gigabytes of memory is free as well as first million executions are also free

Binding to triggers inputs and outputs is very simple. For instance you can bind to a blob storage, so you, can trigger a code whenever there's a new file available on a blob

There's quite a lot of those. I will show you the brief list. So first of all look at this list, and notice that there's first of all two versions of the Function Apps. Version point 1 and version point 2.

In the manage section, you can manage keys. What are the keys for the functions? When you create a function and you had this function code that we are showing at the top you had a get function URL button when you hit it if you would see something like this with the URL to your function

You have a trigger here, you can other inputs, multiple inputs or multiple outputs and for each you can provide a configuration.

I want to create a web hook plus API which is this HTTP trigger so I'm going to hit create..., and in just couple of seconds I'm going to be presented with a standard template for HTTP triggers

Let's be professional so let's go and create function code using Visual Studio Code so how do you do that first of all you go to your Visual Studio Code make sure that you are logged in and you have extensions called Azure account and Azure functions installed

Well the name is not the best but let's change it, ProcessMyBlob... so let's process my blob what is the namespace I'm just gonna leave it as default create local app settings JSON I'm gonna use this storage I need to create a what is the container name I'm gonna call it demo

For all the outputs and inputs besides the trigger we need to specify what is the file access that we're accessing in this case we want to write to the blob therefore we need file access write...

I can run it locally or quickly deploy this to Azure, so let's hit a comment, "dotnet build" after our function function is built we can quickly deploy this to Azure

Looks like we're done if this works we can probably go back to the portal and test it I'm gonna open my storage account into the blob service if you don't know storage accounts I have a great video on storage account introduction that also will be linked down in the comment section

Now back to the blobs go to the output container hit refresh and then just couple of seconds we will gonna get our file here even before I stopped talking we already processed our file

And believe me it's as easy to bind... to any other service that you seen from the list that I presented previously

Transcripts

play00:00

hey there this is Adam again and today we're going to be talking about serverless

play00:03

because it's probably one of the best concepts about the cloud. Managing the

play00:08

code without managing the servers or the infrastructure and everything at scale

play00:12

well what's not like it.Today we're gonna get introduction into Azure

play00:16

function apps. Probably one of my favorite services, so stay tuned.

play00:21

play00:28

So let's start with functions. Functions is a service for running small pieces of code

play00:32

so you have that script in dotnet or maybe java or any other languages that

play00:37

is supported and this is the place to go and they call those small pieces of code

play00:41

functions. This is a great service and very cheap service, very scalable service

play00:46

for running serverless, because you don't have to manage infrastructure underneath

play00:50

what is important is that this service is extension of Azure App Service, so if you

play00:55

want to know all about features that this service has because this is an

play00:59

extension of the App Service I highly recommend you to watch the video on the

play01:03

App Service which will be linked down in the comments. So why would you use

play01:09

Function Apps well they have a lot of features like multiple languages, they

play01:14

support C# in both DotNet and DotNet Core frameworks, Java, JavaScript

play01:20

Typescript which is transpiled to JavaScript

play01:23

you have PowerShell Core, you have F# and Python, so a lot of languages

play01:28

that you can use and other that are popular recent days, you can use here, but

play01:33

additionally you can pay per use so the price is super super cheap because first

play01:40

four hundred thousand gigabytes of memory is free as well as first million

play01:45

executions are also free, so you probably will use functions in most cases without

play01:51

paying a dime. So I would say that's a great price, but if you extend and you go

play01:58

further beyond that the price is still very small because million executions

play02:03

cost 169 cents. Additionally you have your own

play02:10

dependencies that you can bring either using NPM

play02:13

or NuGet you also have integrated security this is coming from the

play02:18

App Service. You have this integration with Azure Active Directory or any other external

play02:23

provider. You have simplified integration because you can combine this with

play02:29

external tools. You have flexible development, because you can develop in

play02:35

the portal on maybe Visual Studio code or any other tool in that matter. But

play02:40

also you have integration of GitHub, Azure DevOps and other external repositories

play02:44

and this is again one of the key features that came from this being an

play02:48

extension to the App Service and lastly we have this as an open-source because

play02:56

entire SDK for functions is open-source so you can find it on a GitHub. So we

play03:03

were talking about this simplified integration I didn't say much because I

play03:06

have a lot of slides on the simplified integration and let's talk about this

play03:11

now. So how function works. Function is a piece of code, we already said that, but

play03:16

in order to execute that piece of code you need something called trigger.

play03:20

A trigger is an action that will involve this code and will pass some basic

play03:26

information to this code in order to run and of course code when it's done it has

play03:31

some sort of an output because why would you run it if it didn't have an output.

play03:36

So the simplified integration is this part where binding to triggers inputs

play03:43

and outputs is very simple. For instance you can bind to a blob storage, so you

play03:48

can trigger a code whenever there's a new file available on a blob and you can

play03:53

maybe process that file and put it back on a blob storage. What is great here is

play03:58

that you are not limited to one trigger and one output... or well trigger can only

play04:05

be one. There's always one trigger, but you can also have multiple inputs so you

play04:10

can maybe grab additional data from your cosmos DB while processing this blob

play04:16

storage or maybe you can grab some additional info from the queue store and

play04:23

this is not where it ends, because you can also have multiple outputs. So maybe

play04:26

you process this file and grab some information from the queue now you can

play04:30

also output this to the blob storage, maybe save some additional logging into

play04:34

another blob storage and put some events for other applications to know that your

play04:40

finished processing on the event hub. So all those integrations are very very

play04:45

easy and I will show you why. So let's grab the most simple example, so we're

play04:52

processing data from the blob storage and we want to output into the blob

play04:56

storage. How do we do this? I will use a DotNet Core as an example, but it's as

play05:02

easy in any other language as it's in DotNet Core. You just grab a documentation and

play05:08

check what's the difference but the principle stays the same. So this is the

play05:15

piece of code that grabs the file from the blob as a trigger. So you have a blob

play05:21

trigger... defined here and you do it in a way that you pass a parameter and you

play05:30

specify blob trigger. That tells our function that we are triggering every

play05:34

time there's going to be new file on the blob storage.

play05:37

Second of all you specify in which container should you check. In this case

play05:42

it's going to be "sample-workitems". So function will check whenever there are

play05:47

new files in this container and trigger whenever new file appears or is modified.

play05:54

Next... You have something called expressions, so in this case use

play06:00

expression to grab the name of the file that is being processed. What is good

play06:05

here is that you can use this expression to pass the name of that file into a

play06:10

variable of the same name. That means in this name variable right now in this

play06:15

parameter, You will have the name of the file or actual full path to the name in

play06:21

that variable. Next and lastly for this trigger you need to define a variable

play06:28

that you will put your contents of the file in. In this case it's a stream so

play06:33

we're going to put the file and all its contents in

play06:36

"myBlob" parameter,

play06:40

and lastly if you want this output you just add additional line

play06:44

saying "Blob", this is no longer trigger switch, it's just a blob. You specify the

play06:49

container name, You specify the file access which is in this case writing

play06:54

because we were processing the file. And you can just type a "blob.copyTo(outputBlob)"

play06:59

and this is with... one line of code you're making a copy of blob into

play07:05

additional container into additional storage. This is as easy as you see.

play07:11

You just type in one binding, because every this line that you see here, "BlobTrigger"

play07:17

"Blob", those are bindings.

play07:19

So just give one line

play07:20

of binding and just type your code and it does all the connectivity, all the

play07:25

file... uploading, downloading, all those kind of actions for you and it's as easy

play07:31

as it gets for any other binding, for any other service. So if this is so easy

play07:41

what kind of triggers and bindings do you have available at hand. There's quite

play07:46

a lot of those. I will show you the brief list. So first of all look at this list

play07:51

and notice that there's first of all two versions of the Function Apps. Version

play07:56

point 1 and version point 2. I would say go for version point 2, because it's that

play08:02

direction that Microsoft is going and it's probably gonna be long-term living

play08:06

support here. Much longer than a version first and there's a lot of new features

play08:11

coming in to point out that are not available in point 1. But also notice

play08:16

that all those services not always can be also input and output because of

play08:22

those... how those services work... best example of this is even grid on the left

play08:28

hand side because it can be a trigger but it cannot be output or input. So you

play08:34

can trigger your functions based on the events from the event grid, but you

play08:38

cannot output into the event grid... yet. So you have of course Blob storage, Cosmos DB,

play08:45

Event Grid, Event Hubs, HTTP and web hooks; those are

play08:49

standard this is not a service binding this is just a binding for you to create

play08:54

your HTTP RESTful services. You also have integrations with Graph. Graph is a.. crazy

play09:02

good API delivered by Microsoft to manage all things about Office and Azure

play09:08

Active Directory, so you have Excel tables OneDrive files, Outlook email, some events

play09:13

from the Graph you have tokens, but also you have Mobile App Service, you have

play09:19

Notification Hubs, Queue Storage, Send Grid, Service Bus, SignalR, Table

play09:24

Storage, Timer which means you can actually do scheduled processing and

play09:28

Twilio. So a lot of bindings for you to use and a lot of flexibility coming with

play09:35

them. So let's go into the portal and start creating the service. In order to

play09:43

create new service you need to hit create resource and type function...

play09:52

Hit create. You need to provide the name. I'm gonna call it "a4edemoapp". I need to

play10:02

select a resource group I already have one existing, so I'm gonna choose that.

play10:05

I'm gonna leave OS as windows. I'm going to leave consumption plan. Consumption plan

play10:11

is this serverless plan, which means you don't manage any servers. Azure will give

play10:17

you servers whenever there's a processing happening, whenever there's

play10:21

not it will take away those servers. So have between 0 and 200 servers available

play10:26

at hand and of course either decides whenever you need those 200 servers or

play10:31

not. If you're going to be processing a lot of data Azure will keep giving you

play10:36

additional servers and your data will be processed faster. Next we need to pick a

play10:41

location. I'm gonna pick North Europe, this is my go-to choice because it's the

play10:47

closest data center of me. I'm gonna choose runtime stack .Net Core I'm

play10:52

gonna choose storage. Interesting... why do I need a storage? Because everything that

play10:59

you're doing functions including functions code is stored on

play11:03

storage, as you can imagine since functions are serverless you don't have a

play11:08

server therefore, you don't have any place where you can put your code in and

play11:11

save your state. This is where storage comes in. An entire code base of your

play11:17

functions and the state of your functions are saved on the storage. So

play11:22

whenever new servers are initialized they grab the code from this storage, and

play11:26

lastly you have Application Insights, a great service for logging and telemetry

play11:30

but this is not a part of the demo today. So let's hit create.

play11:38

The deployment

play11:39

happens in about 2-3 minutes because three services needs to be deployed so

play11:43

I'm gonna speed this up

play11:53

So the deployment finished, so we can go to our resource group open it find a

play11:58

function up including that storage that we created and application insights I'm

play12:03

gonna go to App Service, and this is the default UI that you will be presented in

play12:08

that... when you create functions. So let's go back to our presentation and I will

play12:13

talk briefly about the features that you can find here in the portal.

play12:21

So what are the top features? First of all when you are presented with this you will have a

play12:25

list of the Function Apps and for each Function App you will have an overview

play12:29

table and a platform features tab. In an overview tab you have a most basic

play12:34

information about the Function App like the URL of the Function App, what is the

play12:38

pricing tier and App Service plan, what is the resource group that is hosted, what

play12:43

is the current status, which in our case it's running, but you also have... something

play12:50

important in the platform features, because in the platform features you

play12:55

have much more options, like all the options coming from the App Service, but

play13:00

also, one key feature here is the Function App settings, I'm not going to

play13:05

talk about all those options here. Because they are coming from the

play13:08

App Service. If you want to learn more about most of them, go to my video on the

play13:13

App Service, but for today we're just focusing on this one Function App

play13:18

settings. So in the Function App settings you will get the most basic information

play13:24

about the... let's say crucial part of the environment setting. Like daily quota is

play13:30

here, the runtime configuration which is this 1.0, 2.0 version that we're talking

play13:35

about when we are talking about the bindings. You also have read-only mode

play13:40

here and if you want to change your application that no one can modify it

play13:45

you also have your host.json file here, but I will talk about host.json file

play13:50

later on... additionally when you have a functions already deployed in the

play13:58

functions tab you can find all those function you can change the state of

play14:01

each function you can either disable it or enable it you

play14:05

can create new functions from here of course this is not the professional way

play14:10

of developing functions but you can in fact develop functions in a portal.

play14:15

This is great for a quick prototyping but still considering how fast it is to

play14:19

deploy it from visual studio I would never use portal anyway. So when you hit

play14:24

new function you'll be presented with the templates for this function you have

play14:28

HTTP templates, you have timer template service bus, queues, and a lot of more you

play14:34

just hit one of those provide some basic information and you will get the

play14:38

function like this... so HTTP trigger function when you deploy it you will see

play14:43

something like this. This is the out-of-the-box template using CSX which

play14:48

is like scripting C# file. I would say it's not the best to develop

play14:54

production applications, but it's good for every now and then... And of course you

play15:01

have an additional tab called "test", so you can quickly test your functions also

play15:05

in the browser. So it's like a small integration developed an environment for

play15:09

you in the browser to do a quick POCs, quick testing and quick functions.

play15:16

Next in this function inside of it you have three tabs. One called "integrate", this is a

play15:21

visual way to add those bindings that we're talking about. You have a trigger

play15:25

here, you can other inputs, multiple inputs or multiple outputs and for each

play15:30

you can provide a configuration. For instance when hitting on the input you

play15:34

will get the list of that standard input that you can use like a blob storage,

play15:37

table storage, authentication tokens from Graph, etc. Next you have a manage section

play15:44

In the manage section, you can manage keys. What are the keys for the functions?

play15:50

When you create a function and you had this function code that we are showing

play15:56

at the top you had a get function URL button when you hit it if you would see

play16:01

something like this with the URL to your function but what you wouldn't see at

play16:06

first it does there's a very long code attached to your function this is

play16:11

authorization code that allows you to call this through the public Internet

play16:17

and you have also monitor tab... in which you can see all the executions for your

play16:25

functions this is a very very small very basic feature is just a date

play16:31

operation ID duration code but if you want to see full telemetry for your data

play16:36

you just go to application insights since we provision this together and

play16:41

that's it in terms of portal features but one last thing that I want to talk

play16:45

about is this host configuration file. Because this host file that we are

play16:51

talking about in the function app settings is the file that controls how

play16:57

your entire functions work for instance one of the sections that you can apply

play17:02

there is HTTP section this is the section that will control how your HTTP

play17:07

trigger works first of all it defines the route it says that the prefix for

play17:12

the route is always slash API which is good to always notify your customers and

play17:18

your clients that this is the URL for the API

play17:22

you also have max outstanding requests count, this is how many requests can

play17:28

there be queued before your requests will start getting responses TooBusy

play17:34

from the service, and also you have max concurrent requests and this is the

play17:39

count of how many parallel executions for the functions can happen at the time

play17:44

in this case it's a hundred which means we can have 100 functions running at the

play17:49

same time so let's go further and talk about this file but remember this file

play17:58

is available in the function app settings if you're working in the portal

play18:02

this is place where you change it but if you're working with a code then this is

play18:07

going to be part of your code base in your project so let's go back to the

play18:15

portal since we've seen how to work with this, let's create a quick function so

play18:19

let's go to the function tab let's hit this button to create new function from

play18:24

the quick start we're gonna choose that we want to develop in the portal I'm

play18:28

gonna hit continue I want to create a web hook plus API

play18:33

which is this HTTP trigger so I'm going to hit create...

play18:41

and in just couple of

play18:42

seconds I'm going to be presented with a standard template for HTTP triggers

play18:51

okay I've got it and notice that it is tiny bit different that what we were talking

play18:58

about because you have here "HTTPRequest" it's not "HTTPTrigger" and a...

play19:03

this is simply because working with HTTP is tiny bit different than working with

play19:08

other triggers but don't worry about it this is the most simple version of the

play19:12

HTTP function that you can write, so you have some logging here that we've been

play19:17

processing the request this says that grabbed a URL parameter called name if

play19:23

there is some parsing and if there's no name in the URL return the

play19:30

message that URL needs to be submitted if it is say hello and name, so let's see

play19:35

if this works you can test it two ways you can either open this panel on the

play19:39

right hand side click on the test tub and send a request body or a URL

play19:44

parameter scroll down this UI is known that the best but there's a run button

play19:50

here executed and we got hello Azure... so it works but you can also test it just

play20:00

by grabbing a URL yourself going to another tab pasting the URL hitting

play20:05

Enter of course please pass the name query string we didn't do that

play20:10

so let's do that

play20:16

so my name is Adam and hello Adam

play20:20

so you see it works and we got logs here we could console everything that we

play20:25

do we can see here quickly at glance so of course you could stay here and start

play20:33

the hoping here and notice how easy it is to actually create your HTTP type

play20:38

functions but let's be professional so let's go and

play20:43

create function code using Visual Studio Code so how do you do that first of all

play20:50

you go to your Visual Studio Code make sure that you are logged in and you have

play20:55

extensions called Azure account and Azure functions installed including all

play21:00

the CLI tools for the functions when you do you log into your functions and your

play21:07

portal and in your subscription you should be able to find the function that

play21:11

you created let's refresh so we have our a4edemo application this is all the

play21:18

function that i have access to so what we need to do right now is go to

play21:23

Explorer this is the empty demo folder and then I created and you need to

play21:29

initialize new project I do that by hitting F1 and typing functions so if you

play21:37

have an extension installed you see all those options here I will hit create

play21:42

function option it says that I need to initialize the project which I'm gonna

play21:46

say ok I want to use C# because today's demo is part of the .net core

play21:53

I want to trigger let's maybe do a scenario where we're gonna trigger from

play21:58

the blob, we're gonna process this blob and output it back into the storage so

play22:03

I'm gonna hit blob trigger well the name is not the best but let's change it

play22:09

ProcessMyBlob... so let's process my blob what is the namespace I'm just gonna leave it as

play22:18

default create local app settings JSON I'm gonna use this storage I need to

play22:27

create a what is the container name I'm gonna call it demo and for local

play22:38

development you need to select if you're using live storage account from Azure or

play22:42

if you're using local emulator I'm gonna choose local emulator because it's

play22:47

much better and what to do with the file that we're going to create opening

play22:52

current window

play22:55

it was quite few options to click at start but we're done and let's see what

play23:01

the template created for us first of all you hit here enter and here and here we

play23:10

see that have we have three parameters for blob so we have a connection name we

play23:15

choose the connection we have a demo so let's talk about what do we have here

play23:23

first of all blob trigger which means this function will run every time

play23:27

there's a new file this file has to be on the demo container on a storage that

play23:32

is supplied in this connection setting and the name of the file will be passed

play23:38

into name parameter so what we need to do here is we probably could just deploy

play23:45

this right now but what I want to do is I want to actually remove this setting

play23:50

because I don't want to create new storage account I want to use this

play23:56

setting use AzureWebJobsStorage so you can quickly change that by changing

play24:00

this connection name here so that means we're going to connect the blob but how

play24:05

to connect to this blob we're going to use connection specified by app setting

play24:10

called AzureWebJobsStorage if you want to talk

play24:13

about and here about the app settings go again to the video on the App Service

play24:19

Plan and App Service in general and you will see how this binding is done

play24:24

because this is also one of the features coming from the app service so we're

play24:29

gonna grab this connection string which means in the local development we're

play24:33

gonna use local storage in the portal we're gonna use the storage attached to

play24:39

our functions so let's hit save here let's do one more thing let's do a demo

play24:46

where since we're gonna be processing this file and we can already do

play24:50

something about it like I don't know... grab the length of this file like var len

play24:56

equals this right so this is gonna grab the length of the file from our stream

play25:03

and put it in the length variable so if you want to output something into

play25:08

Blob again we need to go here the easiest is just copy this line and change few

play25:14

things about it so let's remove trigger because this is no longer trigger it's

play25:18

gonna be output lets outputs... lets output something in two different container

play25:24

maybe call that container output let's leave the name as the same as the name

play25:33

of the file we started processing and let's change the variable to outputBlob

play25:42

so what do we do right now let's do most simple example where I'm gonna grab my

play25:48

blob type copyTo and let's copy it to outputBlob

play25:58

one thing that we're missing here is file access because for all the outputs

play26:03

and inputs besides the trigger we need to specify what is the file access that

play26:07

we're accessing in this case we want to write to the blob therefore we need file

play26:12

access write...

play26:21

this should be fine and we should be able now to run this function

play26:25

I can run it locally or quickly deploy this to Azure, so let's hit a comment

play26:29

"dotnet build" after our function function is built we can quickly deploy this to

play26:39

Azure I'm pretty confident this will work so let's try it... we go to our Azure

play26:46

extension we right-click on our application click deploy to function app

play26:54

it will say if you are sure that you want to override existing functions... well

play26:59

I am sure... so let's go for that and the first deployment takes about a minute or

play27:07

two so let's speed this up

play27:14

looks like we're done if this works we can probably go back to the portal and

play27:19

test it I'm gonna open my storage account into the blob service if you

play27:26

don't know storage accounts I have a great video on storage account

play27:30

introduction that also will be linked down in the comment section so feel free

play27:34

to check it out for now I'm gonna create two containers as we specified one for

play27:38

the input which is called demo and one for the outputs called output so if my

play27:51

function is working fine I can go to demo hit upload a file select one of

play27:58

that files maybe my file with my code

play28:04

now back to the blobs go to the output container hit refresh and then just

play28:10

couple of seconds we will gonna get our file here even before I stopped talking we

play28:15

already processed our file and I can open this file here and check that we

play28:20

have entire content of our file copied successfully to another container it was

play28:25

this easy to bind two blobs process something with them and output back to

play28:30

the blob storage and believe me it's as easy to bind... to any other service

play28:35

that you seen from the list that I presented previously as you have seen

play28:41

serverless is not that hard you just type few lines of code and it's working it's

play28:45

very cheap very flexible very scalable service that you can use in minutes so

play28:51

if you know any of the programming languages just go ahead and start doing

play28:54

it it's very satisfying if you liked this video hit thumbs up leave a comment

play28:58

and if you really liked it if you want to see more videos hit subscribe and I

play29:03

guess see you next time