So let's talk about AWOL Linda versions because as soon as you start working on limbs of functions and
put him and death tests brought.
This is where functions and aliases that was in the next line are really really important.
So when you work on the function you work on the version called latest and that makes sense.
The latest version is what you modify and so lettuce is mutable mutable means that we can change it
as we want when we're ready to publish dysfunction when we are happy with the status of this function
we can publish it and create a version.
So the first version we create will be the one for example.
And that version is immutable.
That means that the V1 we cannot change it ever is the snapshots and versions gets increasing their
numbers.
So after V1 we will have V2.
Now the versions each of them will get their own HRN Aaron is Amazon resource name.
So that means we're able to address either V1 or V2 or latest based on different ends.
And the version is the code itself and the configuration.
So environment variables time outs et cetera nothing can be changed.
Everything is immutable.
And so each version of the land the function including latest can be accessed whenever you want using
the correct A R.
So now workflow when we work and we're happy with a state of LMA function we say okay we'll going to
snapshot latest and we're going to create a new version out of it.
Why would we do this.
Well we create versions in order to have a dev environment a test environment and a prod environment.
Right.
But so if we have new versions of the time we have to rewire everything in dev test prod all the time.
And that may be super painful.
Instead we can use lambda aliases and so aliases are pointers to lend the function versions.
So versions where immutable and aliases are not.
So we can define for example a dev test and prod alias and we punted them to different lambda versions
and we can change these pointers over time because they're immutable.
So here is our latest lambda function version it's mutable.
But we also have V1 and V2.
Now we can create a dev alias which represents our development environment which most likely we want
to point at the latest function we have.
So we'll point the dev alias to latest.
Now our users when they interact with our function that don't directly interact with the latest version
they interact with the dev alias Now we also have a test alias maybe.
And we're actually testing our V2 of our function.
So the test alias may point to the V2 and maybe we have a prod function and the proud alias is going
to point directly to V1.
So as you can see all the aliases are mutable whereas the versions are immutable.
And so if we want to do blue green deployment or updates are proud environments to migrate it from the
one to V2 because it turns out it was great.
We can do a deployment and assign weights so we can say the proud alias Ninety five percent of this
is going to point to view 1 and 5 percent of it is going to point to V2.
This way we're going to test with a little bit of traffic how the V2 function is doing.
And so using this we can do blue green deployments our users don't know what's happening at all because
the only thing they interact with is the aliases.
So for the users nothing changes.
And so we're able to iterate basically in the backend while providing a stable configuration for our
users are even triggers in our destinations so we can change all we want and rewire the aliases to functions.
But for the users the endpoints are the same.
And that's because aliases will have their own HRN So that makes sense.
We will go right now into a hands on probably to give it a bit more clarity.
So now let's play with these versions and aliases so let's modify our function a little bit make it
a bit more simple.
So I'm going to remove everything about the environment variables and I'm going to just import Jason.
Here we go.
And the return is going to be something very simple.
I'm going to return.
Hello world.
OK.
And so this is our function this returns of the world and you save it and everything works fine.
And so if we test it it should go ahead and says hello world excellence.
Now let's go look at qualifiers.
So we have our versions and then we have aliases and so both are saying latest and latest.
But what we should do now is publish our first lambda version.
So we're very happy with this function.
We're very happy would does.
So I'm going to go ahead and click action and publish new version and I'll call it version 1 and publish.
Here we go.
So my first version called one and the description is version 1 has been created 31 seconds ago.
And we're very happy with it.
And this is our version 1.
And this is immutable.
So I'm trying right now to change the code but I cannot.
OK.
So once you publish a version the version cannot be changed at all.
So now version 1 is lambda dummy and contains this code and cannot ever be changed to change the code.
We need you go to latest.
So we switch to version latest and here we're able to change the code.
So maybe I'll say goodbye world and save this function.
So now we have saved latest and to publish this new version I click on published new version and I call
it updated lambda function to say goodbye.
OK.
And click on publish.
So now we have to them the functions we have Version 1 and 2 version 1 says how the world and this one
says goodbye world we can test it and say Yes this one says goodbye world excellence.
So now how do we go about creating aliases.
So this is our development cycle we keep on creating new versions.
But what we'd like to have is a dev and a prod alias.
Right.
So let's go through actions and create an alias and the first one is going to be called dev and Dev
aliens make sense.
Dave is the latest version of our lambda function and the version is going to point to is latest.
OK.
So what Cregan creates.
And now any time we refer to the alias Dev this is going to point to the latest version.
So if we make some modification to latest so let's go ahead and our function and make some modifications.
So I will grant your rights 42 and click on Save and now test its function.
So this function returns 42.
And if you click on the alias dev and test this function it's also going to return 42 because our alias
dev is pointing to the latest version.
But we're going to create another alias.
We're going to create the proud alias.
And this one is our most stable version of our lambda function.
And the version is going to point to is version 1.
And the second creates.
So now we have the proud alias and the proud alias right now as you can see is pointing to version 1.
But the idea with aliases is that if you look at the air and hear the kind of a version has the version
number at the very very end and if we look at the aliases for at the age and four aliases we can see
that now there's death in the back and also prod in the back at the end of the E.R..
So now we can point our functions not just two versions but also two aliases and have the aliases point
to versions just the way we saw it in the slides from now.
OK.
So this is good right.
But what if you won't you release a new version.
So we're very happy with the way that is going and we want to promote diversion too into pride.
So to do this I'm going to just call down and we can see here the alias configuration.
So we are viewing the configuration for alias pride and we can manage a configuration for version 1
if you click on that link but we'll stay here in this page.
So proud is our most stable version for our lambda function and currently it is pointing to Version
1.
But maybe we want to also pointed to version two and we'll say that's 10 percent of the traffic should
go to version 2.
So now what we have is version 1 serving the 80 percent or 90 percent sorry of the traffic and version
2 serving 10 percent of the traffic based on the weights we assigned.
So this way we are doing some blue green testing.
OK we're trying to see if the green versions or the newer version is working just fine.
So I click on Save and now any time we invoke prod 90 percent of the time we'll have version 1 and 10
percent of the time we'll have version 2.
And if we're happy we can switch this all the way to 100 if we want to switch all the way you earned
to right or we can just select version 2 in here and be done with it or we could say for example after
10 percent I want to test a little bit more load.
So I'm going to say 50 50 science or 50 loops I cannot enter 50.
So I can enter the 5 and then the zero.
Here we go.
I mean we'll transfer 50 and so in here we have 50 50 of the weights and now 50 percent of the time
version 1 will be invoked in 50 percent of the 2 of the time version 2 will be invoked.
So let's say this and let's test our product click on Test and here we get how the world and I'll test
again.
We get good by world.
So this is excellent.
And in the log outputs we can see which version was invoked.
So here it is version 2.
But if I test again and a few times we should start seeing at some points of Hallowell.
Here we go.
Hello world.
And then we have version 1.
So here using these weights we're able to test the traffic to a new lambda version.
And when we're ready to promote version 2 to prod it We'll click on version to click on Save and I'll
set the weight to zero and I'll set additional version to none.
Here we go.
So we just have Version 2 in here.
Now click on save.
And now this has been saved.
So proud is only pointing to version 2.
And now if I invoke my function I only get good by Weld so using aliases we're able to use a bit more
weight deployments for our Linda functions.
And that's really really good.
And does that remind you something maybe you've been burning for me to say it's for all along.
And I hope it did remind you something.
But remember we went to code deployed for lambda functions so we had our deployments configurations
and for lambda so o filter for lambda we had all at once where we update dilemma function all at once.
But we also had lambda linear 10 percent every 1 minutes and this actually under the hood is using this
very same feature where we have percentage of weights in here.
So this configuration of code deploy in here is actually adding 10 percent everyone minutes to this
configuration.
And here is lambda linear 10 percent every two minutes and so on and so linear remover means that we
go and we start at 10.
Then we'll be at 20.
So 20 and then we'll be at 30 and so on.
And when we have a Kennedy deployment which is here land that can every 10 percent 15 minutes.
That means that we'll be at 10 for 15 minutes.
And right after we'll be at 100 percent because it can every day appointments is a two step thing.
Okay.
Whereas linear is gradual.
So super important you see this how could deploy configurations for the deployments.
Do tie in to this feature of Alias and versions and something they want you draw your attention on.
So that's it for this lecture.
I hope you liked it and we'll see you in the next lecture.