1 00:00:00,310 --> 00:00:02,780 ‫Okay, so let's practice versions in Lambda. 2 00:00:02,780 --> 00:00:03,947 ‫So let's call this function: 3 00:00:03,947 --> 00:00:05,747 ‫"lambda-version-demo". 4 00:00:06,610 --> 00:00:08,690 ‫We'll use Python 3.8 5 00:00:08,690 --> 00:00:12,080 ‫and create our function. 6 00:00:12,080 --> 00:00:14,180 ‫So versions are here to allow us 7 00:00:14,180 --> 00:00:17,800 ‫to fix a amount of code and removables 8 00:00:17,800 --> 00:00:19,560 ‫and settings in time, 9 00:00:19,560 --> 00:00:21,920 ‫and say you are a specific version. 10 00:00:21,920 --> 00:00:24,480 ‫And the idea is that we want to author our versions 11 00:00:24,480 --> 00:00:27,200 ‫over time to allow our lambda function to evolve. 12 00:00:27,200 --> 00:00:28,550 ‫So let's have a look 13 00:00:28,550 --> 00:00:30,850 ‫and we're going to take our function code, 14 00:00:30,850 --> 00:00:32,550 ‫we're going to just return something simple. 15 00:00:32,550 --> 00:00:33,803 ‫So we're going to return: 16 00:00:34,807 --> 00:00:36,917 ‫"this is version one." 17 00:00:37,870 --> 00:00:41,233 ‫And then we're going to deploy and test our changes, 18 00:00:42,220 --> 00:00:43,620 ‫create a sample event, 19 00:00:43,620 --> 00:00:45,820 ‫create, test 20 00:00:45,820 --> 00:00:47,980 ‫and we get "this is version one." 21 00:00:47,980 --> 00:00:50,640 ‫So say we're very happy with this code 22 00:00:50,640 --> 00:00:52,040 ‫and we want to author this 23 00:00:52,040 --> 00:00:54,070 ‫as the version one of our function. 24 00:00:54,070 --> 00:00:57,760 ‫So we can do "action" and then "publish new version." 25 00:00:57,760 --> 00:00:59,150 ‫So this is going to be version one. 26 00:00:59,150 --> 00:01:02,570 ‫We can add a description and we just click on "publish." 27 00:01:02,570 --> 00:01:03,403 ‫And here we go, 28 00:01:03,403 --> 00:01:06,140 ‫the version one of our function has been created. 29 00:01:06,140 --> 00:01:07,480 ‫So what has changed? 30 00:01:07,480 --> 00:01:09,500 ‫Well, now we are in the function overview 31 00:01:09,500 --> 00:01:12,210 ‫at lambda-version-demo, and there's a one here 32 00:01:12,210 --> 00:01:14,600 ‫so this is lambda version one. 33 00:01:14,600 --> 00:01:16,320 ‫And if we go to the code itself 34 00:01:16,320 --> 00:01:18,720 ‫it says that the designer is only available, 35 00:01:18,720 --> 00:01:20,380 ‫we can only change it when we are on 36 00:01:20,380 --> 00:01:21,570 ‫the unpublished function based. 37 00:01:21,570 --> 00:01:23,980 ‫So when we're on latest, but because we're on version one 38 00:01:23,980 --> 00:01:26,700 ‫we cannot change the code in here. 39 00:01:26,700 --> 00:01:28,480 ‫So we can test this function. 40 00:01:28,480 --> 00:01:29,700 ‫We can test it right here 41 00:01:29,700 --> 00:01:32,020 ‫and it says, yes, look at this. 42 00:01:32,020 --> 00:01:32,970 ‫This is successful. 43 00:01:32,970 --> 00:01:35,360 ‫And it says, "this is version one." 44 00:01:35,360 --> 00:01:36,470 ‫So this is great! 45 00:01:36,470 --> 00:01:38,810 ‫But now say we want to keep on editing our functions. 46 00:01:38,810 --> 00:01:40,850 ‫So we go back to our main function 47 00:01:40,850 --> 00:01:42,130 ‫and then we're going to edit it 48 00:01:42,130 --> 00:01:44,590 ‫and say, "this is version two." 49 00:01:44,590 --> 00:01:47,640 ‫We're going to deploy this and then test our changes. 50 00:01:47,640 --> 00:01:49,580 ‫So let's go to "test" and then test. 51 00:01:49,580 --> 00:01:52,280 ‫Now it says, "this is version two." 52 00:01:52,280 --> 00:01:53,113 ‫Great. 53 00:01:53,113 --> 00:01:55,650 ‫So let's publish this new version because we like it. 54 00:01:55,650 --> 00:01:57,250 ‫So let's publish it. 55 00:01:57,250 --> 00:01:59,100 ‫And then "publish." 56 00:01:59,100 --> 00:02:00,790 ‫Now we have the version two 57 00:02:00,790 --> 00:02:03,650 ‫of our function "lambda-version-demo," 58 00:02:03,650 --> 00:02:05,080 ‫and it's available right here. 59 00:02:05,080 --> 00:02:06,970 ‫The code is slightly different, 60 00:02:06,970 --> 00:02:09,140 ‫obviously, because now it says, "this is version two." 61 00:02:09,140 --> 00:02:11,563 ‫We can't edit it, but we can test it. 62 00:02:12,537 --> 00:02:13,840 ‫We test this function 63 00:02:13,840 --> 00:02:15,400 ‫and now we're good to go. 64 00:02:15,400 --> 00:02:18,120 ‫So the execution to tell is correct. 65 00:02:18,120 --> 00:02:19,130 ‫Okay, great. 66 00:02:19,130 --> 00:02:22,880 ‫So now we need to play with aliases cause right now 67 00:02:22,880 --> 00:02:25,650 ‫we have authored a few versions for another function, 68 00:02:25,650 --> 00:02:27,500 ‫but we want to create aliases so. 69 00:02:27,500 --> 00:02:29,040 ‫First back into our function 70 00:02:29,040 --> 00:02:31,110 ‫we can view all the versions of our function 71 00:02:31,110 --> 00:02:33,320 ‫on the version stabs in here. 72 00:02:33,320 --> 00:02:35,160 ‫So one and two are available in here. 73 00:02:35,160 --> 00:02:37,490 ‫And now we want to play with aliases. 74 00:02:37,490 --> 00:02:39,130 ‫So right now we don't have any aliases, 75 00:02:39,130 --> 00:02:41,200 ‫but let's create an alias. 76 00:02:41,200 --> 00:02:44,600 ‫And the first alias I'm going to create is the "dev" alias. 77 00:02:44,600 --> 00:02:45,803 ‫And the "dev" alias represents that 78 00:02:45,803 --> 00:02:48,870 ‫our function is the most recent. 79 00:02:48,870 --> 00:02:50,160 ‫And we want this to point to 80 00:02:50,160 --> 00:02:52,760 ‫the latest unpublished version of our lambda function 81 00:02:52,760 --> 00:02:56,070 ‫because we want the dev to always point to the latest code. 82 00:02:56,070 --> 00:02:57,470 ‫So we'll click on "save." 83 00:02:57,470 --> 00:02:59,940 ‫And now we have created a "dev" alias. 84 00:02:59,940 --> 00:03:01,260 ‫So we're good to go. 85 00:03:01,260 --> 00:03:02,890 ‫We go back to our function alias, 86 00:03:02,890 --> 00:03:04,690 ‫we couldn't create a test alias 87 00:03:04,690 --> 00:03:06,990 ‫so we'll create "test" alias. 88 00:03:06,990 --> 00:03:10,260 ‫And there's one to point it to the latest published version 89 00:03:10,260 --> 00:03:12,960 ‫so we'll have it as version two. 90 00:03:12,960 --> 00:03:13,970 ‫Click on save. 91 00:03:13,970 --> 00:03:16,530 ‫And so now the "test" alias, if we test it. 92 00:03:16,530 --> 00:03:18,660 ‫So if we want to test that function 93 00:03:18,660 --> 00:03:20,220 ‫so let's test it. 94 00:03:20,220 --> 00:03:21,053 ‫It's successful 95 00:03:21,053 --> 00:03:23,390 ‫and it says, "this is version two." 96 00:03:23,390 --> 00:03:24,350 ‫Great. 97 00:03:24,350 --> 00:03:28,110 ‫And one last alias we may want to create 98 00:03:28,110 --> 00:03:29,240 ‫is the prod alias. 99 00:03:29,240 --> 00:03:31,960 ‫So let's go and create the "prod" alias. 100 00:03:31,960 --> 00:03:33,770 ‫And this is pointing to version one, 101 00:03:33,770 --> 00:03:37,550 ‫so the most stable version of our function so far. 102 00:03:37,550 --> 00:03:38,820 ‫Click on save. 103 00:03:38,820 --> 00:03:41,020 ‫And now if we test the "prod" alias, 104 00:03:41,020 --> 00:03:44,195 ‫obviously we know what the result is going to be. 105 00:03:44,195 --> 00:03:45,300 ‫We get "this is version one." 106 00:03:45,300 --> 00:03:48,620 ‫So we've seen how to create versions 107 00:03:48,620 --> 00:03:51,490 ‫and we've seen how to create aliases. 108 00:03:51,490 --> 00:03:53,550 ‫But now the interesting thing is that with aliases 109 00:03:53,550 --> 00:03:55,670 ‫we can start doing some weights. 110 00:03:55,670 --> 00:03:57,500 ‫So let's go into prod 111 00:03:57,500 --> 00:03:59,430 ‫and let's say that we wanted to, 112 00:03:59,430 --> 00:04:01,250 ‫and let go, let me go back. 113 00:04:01,250 --> 00:04:04,900 ‫So let's go into prod and we want to edit this alias 114 00:04:04,900 --> 00:04:06,780 ‫because we want to upgrade from version one 115 00:04:06,780 --> 00:04:08,510 ‫to version two and prod. 116 00:04:08,510 --> 00:04:09,642 ‫So we'll edit this 117 00:04:09,642 --> 00:04:13,160 ‫and we'll say that now we want a weighted alias. 118 00:04:13,160 --> 00:04:15,340 ‫So you are in version one right now, 119 00:04:15,340 --> 00:04:18,940 ‫but I also want you to go on version two. 120 00:04:18,940 --> 00:04:20,390 ‫And in a normal production setting 121 00:04:20,390 --> 00:04:23,850 ‫you would test maybe 10% of the weights on version two 122 00:04:23,850 --> 00:04:25,500 ‫and 90% of the weight on version one, 123 00:04:25,500 --> 00:04:26,760 ‫just to have a small amount 124 00:04:26,760 --> 00:04:29,230 ‫of traffic go to your new version. 125 00:04:29,230 --> 00:04:30,750 ‫But, because I want to show you how this works 126 00:04:30,750 --> 00:04:33,160 ‫I'm going to do 50:50, which is quite aggressive 127 00:04:33,160 --> 00:04:35,350 ‫in terms of weight distribution, but at least 128 00:04:35,350 --> 00:04:37,970 ‫we'll get 50% of the time version one being invoked 129 00:04:37,970 --> 00:04:40,070 ‫and 50% of the time version two being invoked. 130 00:04:40,070 --> 00:04:41,620 ‫So we'll save this. 131 00:04:41,620 --> 00:04:46,010 ‫So now our alias "prod" has a weight between two versions. 132 00:04:46,010 --> 00:04:48,640 ‫And so if we go to this alias 133 00:04:48,640 --> 00:04:50,730 ‫and now start testing the function. 134 00:04:50,730 --> 00:04:51,960 ‫So I'll test it once, 135 00:04:51,960 --> 00:04:54,160 ‫we get version two. 136 00:04:54,160 --> 00:04:55,580 ‫I'll test it one more time, 137 00:04:55,580 --> 00:04:57,020 ‫we get version one. 138 00:04:57,020 --> 00:04:58,790 ‫So as we can see the traffic went 139 00:04:58,790 --> 00:05:01,640 ‫part on version two and part on version one, 140 00:05:01,640 --> 00:05:02,630 ‫and you can play around 141 00:05:02,630 --> 00:05:04,970 ‫and keep on testing and seeing what the result is. 142 00:05:04,970 --> 00:05:08,240 ‫So we alternate between version two and version one 143 00:05:08,240 --> 00:05:11,590 ‫50% of the time on the one and the other one as well. 144 00:05:11,590 --> 00:05:12,423 ‫Okay. 145 00:05:12,423 --> 00:05:13,630 ‫So this is how alias work, 146 00:05:13,630 --> 00:05:16,550 ‫and then when you're happy with your production 147 00:05:16,550 --> 00:05:17,383 ‫and say okay 148 00:05:17,383 --> 00:05:20,960 ‫now my new function version is working just as expected, 149 00:05:20,960 --> 00:05:24,340 ‫then you take this alias right here, you edit it. 150 00:05:24,340 --> 00:05:25,173 ‫And now you're saying, 151 00:05:25,173 --> 00:05:28,420 ‫okay now I want you not to use any weighted alias, 152 00:05:28,420 --> 00:05:31,867 ‫just go on version two and send all the traffic to it, 153 00:05:31,867 --> 00:05:35,140 ‫"save." And we've effectively updated the prod alias 154 00:05:35,140 --> 00:05:37,510 ‫from version one to version two. 155 00:05:37,510 --> 00:05:39,340 ‫And that's the whole idea behind 156 00:05:39,340 --> 00:05:41,050 ‫all the versioning and aliases 157 00:05:41,050 --> 00:05:43,350 ‫and the flexibility you get with them. 158 00:05:43,350 --> 00:05:45,030 ‫So I hope you liked this lecture, 159 00:05:45,030 --> 00:05:46,980 ‫and I will see you in the next lecture.