bonjour hi welcome to another video of cloud in five minutes I'm Frank Boucher
and today this is an extended version of the previous video so if you want to
learn more about the visual studio extension and how the function works
stay tuned if you are looking for something shorter and faster
straight to the point look at this video it's the short version so now let's
continue the video I'm answering your questions and show you how to unzip any
file using the azure functions in our previous video I show you how to unzip
any file using logic apps the connector used by logic app cut a limit of hundred
Meg's for a file some of you asked me what can I do if my file is bigger than
that so today's demo is an answer for this problem
I will leverage Azure functions that will get triggered when a new file is
created in the blob storage and it will unzip it in another blob storage so
let's get started so today I'm running on a Windows machine and I'm using
Visual Studio code of course you can run that in Mac OS or Linux also in vs code
I will be leveraging the extension as your functions that you can find so if
you go in the extension icon menu here you will find the azure functions
extension you don't need it to deploy functions but I want to show you a few
tricks that I found very useful also you will need to install the azure function
core tools that are available online so depending on your OS follow the
instruction perfect so now since my environment is already pre prepared
let's close this and get ready once the extension is installed you will have a
new button here in the menu a sure you click on that and now you have a new
section functions so first we need to create a function app or a project so
let's create that one is the first icon and I will call it unzip everything you
have multiple options the language I will use c-sharp perfect
now the project is created let's have a quick look first we have a vs code
subfolder where you will find tools to help you debug in and then we have a
gift ignore because I'm in c-sharp I have a CS proj as a project file where I
can see that I'm running the dotnet core app 2.1 and I'm running V 2 as a sure
functions perfect I also have a JSON file and of course the local dot
settings that JSON file that file is very important it's where all the
configuration will be sitting I will get back to you since those sitting by
default or not copied to the cloud and when you're debugging locally you have
some specific things to write it down so now that we have that let's create a
function so now let's go back to the azure extension and we'll create here
the second icon the little lightning with the plus create a function so we
first select the project and then for today's demo I'm creating a blog trigger
because I want the function to get triggered every time a new file is
created inner blob storage and then we provide a name so I will call it unzip
this and I need to provide a name space
now we need to put some app settings so I will just create a new account storage
and resource group and the location now Azure is creating our resources and
should get back to us very soon and voila
asking us the name of the container that we are looking at so I will be looking
in input files well everything is created now here we have a little nuts
petition that specify that if you are not creating an HTTP trigger and that
you want to debug luckily you will need to put something specific in the local
that's setting that jason i will show you what soon
for now we don't need it so now let's see what have been created for us so
first we have our function and I will just move this so the first line you
describe or binding so we see that our blog trigger is looking to the Container
input files with the connection here my zip demo storage this connection string
will be in our local setting that JSON file I will we'll get there later now I
have some code prepared for you I will just paste it and then I will walk you
through so we have a source defining a block trigger I needed a way to define
the destination so I will put some settings in the configuration file so
I'm using the environment here to to set it up so I will need to add a
destination storage and a destination container also in my settings then I
take the name I check if it's a zip file because my code right now is only
supporting that so you guys if you're looking for solution for R or 7-zip or
gzip or something like that you will need to use another library and talking
about library I'm using here the new system IO compression and that one is
perfect for zip so we'll be using that so what I do here is I use the stream
that I received from my trigger and I'll create an archive and then I'm using the
well-known storage call where I create a reference to my first storage account
and then my blob and then my container you could be thinking but Frank well you
could have a binding in and a binding out and you're right but because when
you are unzipping files there are many chances that you have one entry and
multiple out so because of that it's kind of a dynamic out and it won't work
so that's why we are using here the usual code so then if I scroll up a
little for every entry in my archive I will be creating my blob and uploading
it very simple okay so let's save this and now what I need to do is go in
settings so let's go here in the files I need to add my settings and while we are
in the local setting if you are about to debug locally the thing that you need to
put is used development star edge equal true it's a very good practice to debug
locally using the storage emulator because when you're targeting a blob
that is in Azure you have good chance that you're a real function deploy in
Azure is already looking to that storage then the two function will be
conflicting perfect now what I need is deploy so if we go back in the azure
extension I have here the third option a little arrow pointing to the sky I need
to deploy my function so let's do this so first we need to select our
subscription I saw will create a new one we'll call it a sure unzip everything
then I will use my resource group it will be a best practice to separate your
code from your data but because it's a demo we'll put everything in one
resource group same thing for the storage it will be better - it will be
smarter to separate them but because it's a demo I will do everything so now
other resources are created in Azure then our code will be compiled and
finally we'll everything will be deploying perfect so now everything has
been deployed so let's close this so now if I expand this section I will have
here my new AZ unzip everything function app and if I expand the application
setting I will notice that none of my setting has been deployed and that's by
default by default none of those local sitting are deployed in Azure and that's
great so this way you can have different settings locally and in the cloud but we
need it so we'll just copy them and add them and one nice feature of the
extension is you could right click here on application sitting in had new
settings right away so just like this and I will do the same
for all the other settings voila now all our settings are in there
so another nice feature is we could start streaming the logs so the function
is running in Azure we could get the log and see them invidious code very useful
for debugging so let's start that and while it's connecting let's go create
the containers in our blob storage so we'll go in Azure and then in resource
called five minutes here I have my storage account so let's
go into blobs so I will create my output containers and I will also need to
create my input container so okay perfect so now let's put this on the
side okay look like this is running so you know we are connected the stream is
ready so anything that our function see will will see it through here so now
what I need to do is go in our input we are ready to test it and it will upload
a file so I add the file here that is 165 Meg's so larger than 100 I will use
that as a test so upload it so now what we could expect is when this file will
be done uploading it will trigger the functions that will unzip the file and
put everything in the output containers and we should see a trace in our visual
studio code Hey Wow we see her lot so file a 1 that zip has been triggered and
then we see all the file press one by one unzip it and if I go back in my file
double click here and I go in my output container here I have all the files so
you could be using it directly binding on your blood storage you could have a
logic app calling it or you could have an automation that runs every
morning or once a week calling that function to zip house unzipping with you
could clearly zipping a backup or something and having that in the next
video I will show you how to package this to deploy automatically in a CI CD
until then here another video of cloud and five minutes see you - see you soon
bye you