How to use Environment Variables in Azure Functions


hi welcome in another video of cloud in
five minutes I’m Frank Boucher Microsoft Azure MVP based in Montreal in Canada
and today I want to talk about the environment variables and the azure
functions and what you can do with it aussi si vous préféré j’ai une version en francais de ce vidéo cliquez juste ici en haut à droite the azure function are really powerful
and used in many different situation but very quickly to be dynamic
we need to use certain environment variable so today I want to show you
where to find them and see some little things we can do with it so here we are
in the azure portal and we are already in function app so to see the
environment variables we go in the platform feature and here down in the
koodoo interface we’ll click that it will open a new tab we already see the
debug console in a previous video but for today we’ll go in a tab environment
and if we scroll down here you will have a lot of information about your system
and if you scroll down here they are the environment variables so we have many
different things here like the O’s name and the slot name and the version is
running right now so we are in version 1 by default so you will have a lot of
information but how can we use them let’s go back to the function app so
first let’s create a function for today I just need a quick and simple HTTP
trigger so here it is I won’t change anything yet we’ll expand the log and
the test and if I just change that for Frank and I run it as we expect it will
say hello Frank perfect now we’ll add a new section ok
perfect so in this section I will go get the resource group name and the opening
by using the get environment variable and I will pass the name of the variable
those name come from exactly here it’s all uppercase so we’ll use that and
specify that is for the current process then we’ll just add
a log to trace it so if I I will save it and clean and now if I run again my
function will see here that the research group is called in five minutes and the
name the O’s name is exactly that it worked great
now let’s had a little bit more stuff in it
so here I will go get the slot name once I got the name I will check if its
production and if it’s not I will get out of the function otherwise I will
just continue as usual this could be really useful for example if your
function is doing some database backup so when you deploy in staging you don’t
want to trigger a backup of your database so that’s a good way to avoid
work with your nut and production let’s save it okay now we need to create a new
slot but the slot are presently in preview and you cannot create them to
activate this feature you need to go in the function app settings so here it is
slut preview and I need to turn it on will take few second now that the
feature is available we can create our slot so we go back here and we’ll add a
staging slot okay the slot is create now we need to
do the swap to do it will go in the tab overview and here in the top you will
see a swap button so click on that one will open a new blade and then you click
again on the swap button here you will have many different options but for
today the default value are perfect so click OK now will take a few seconds to
do the swapping taking the code from the production and swap it to the staging
swap is completed now let’s go see our functions so we see now the staging is
populated and we have a function here so we’ll click on that
okay so we’ll expand the test section and the log section okay and I’ll just
change it for Frankie and now if I run it as you can see here the function
result is ello you instead of hello Frankie
meaning that the function did not execute until the end and we see that
the slut name was also found right now if you notice my code is gray out
because the app by default when you swap it’s in read-only so you don’t have
conflict when you’re swapping to change the setting again it’s in function
settings and you could swap here need read-only or readwrite functionality
that’s it this is how you use the environment variable and remember to get
it you go in the CUDA interface in the environment tab and err they are I hope
you liked this video and I hope it was useful thank you see you next week

Comments 1

Leave a Reply

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