1 00:00:00,150 --> 00:00:01,890 ‫So back into y API gateway 2 00:00:01,890 --> 00:00:03,440 ‫I want to test canary but I'm gonna make 3 00:00:03,440 --> 00:00:06,210 ‫a few changes to make it very clear. 4 00:00:06,210 --> 00:00:10,370 ‫So, I want to have my current prod stage 5 00:00:10,370 --> 00:00:15,370 ‫to point to the version one of my lambda function. 6 00:00:15,410 --> 00:00:17,210 ‫So I want my prod stage to point to version one 7 00:00:17,210 --> 00:00:18,640 ‫so I'm going to make a change. 8 00:00:18,640 --> 00:00:23,640 ‫I'm gon ago to API gateway and I'm going to create a GET. 9 00:00:24,690 --> 00:00:28,100 ‫And this one, so I will change this integration 10 00:00:28,100 --> 00:00:29,527 ‫so it says lambda proxy, 11 00:00:29,527 --> 00:00:31,772 ‫but the lambda function is going to be authorized 12 00:00:31,772 --> 00:00:36,010 ‫to read into is version one, so I do colon one, 13 00:00:36,010 --> 00:00:39,310 ‫this is version one of my lambda application. 14 00:00:39,310 --> 00:00:41,020 ‫So we're about to give API gateway permission 15 00:00:41,020 --> 00:00:42,930 ‫to invoke our lambda function, where I'll way yes, 16 00:00:42,930 --> 00:00:45,400 ‫you can do this and this is perfect. 17 00:00:45,400 --> 00:00:48,143 ‫So I want to deploy that change into my prod stage 18 00:00:48,143 --> 00:00:52,870 ‫so I will deploy this API into my prod stage 19 00:00:52,870 --> 00:00:54,250 ‫and I'll deploy it. 20 00:00:54,250 --> 00:00:57,640 ‫So this means that if I go to my prod stage now and open it 21 00:00:57,640 --> 00:00:59,300 ‫it says, "Hello from Lambda" 22 00:00:59,300 --> 00:01:01,121 ‫and it should say version one very very soon 23 00:01:01,121 --> 00:01:03,087 ‫so let's wait a little bit, here we go. 24 00:01:03,087 --> 00:01:05,790 ‫"Hello from Lambda version one" so my prod stage 25 00:01:05,790 --> 00:01:07,480 ‫is now pointing to version one 26 00:01:07,480 --> 00:01:09,240 ‫and I want to be able to test the version two 27 00:01:09,240 --> 00:01:10,590 ‫of my Lambda function. 28 00:01:10,590 --> 00:01:13,430 ‫So for this I'm gonna go and create a canary, 29 00:01:13,430 --> 00:01:17,510 ‫create a canary, and now we can configure the canary itself. 30 00:01:17,510 --> 00:01:19,000 ‫So what's the percentage of traffic 31 00:01:19,000 --> 00:01:20,390 ‫I want to redirect to my canary? 32 00:01:20,390 --> 00:01:22,760 ‫So in the real world you would say something like 5 percent, 33 00:01:22,760 --> 00:01:25,140 ‫a very small amount, but for us because we want 34 00:01:25,140 --> 00:01:26,490 ‫to be able to shown you how that works, 35 00:01:26,490 --> 00:01:29,660 ‫we'll say 50 percent, so that 50 percent of the traffic 36 00:01:29,660 --> 00:01:32,970 ‫will go to my canary and 50 percent will go to prod. 37 00:01:32,970 --> 00:01:35,040 ‫We haven't done any canary deployment just yet, 38 00:01:35,040 --> 00:01:36,517 ‫so we'll need to do one right now, 39 00:01:36,517 --> 00:01:37,910 ‫and for the stage variables 40 00:01:37,910 --> 00:01:39,670 ‫we could override them for the canary, 41 00:01:39,670 --> 00:01:42,045 ‫but this is not necessary for this hands-on 42 00:01:42,045 --> 00:01:44,850 ‫as well as we can use a stage cache. 43 00:01:44,850 --> 00:01:46,550 ‫So let's do our canary deploy 44 00:01:46,550 --> 00:01:48,560 ‫so I'm gonna go back to my resources, 45 00:01:48,560 --> 00:01:50,553 ‫go to my first GET at the root 46 00:01:50,553 --> 00:01:52,900 ‫and then we'll change the integration request 47 00:01:52,900 --> 00:01:55,153 ‫and now it'll say version two. 48 00:01:55,153 --> 00:01:58,790 ‫I will save this, so I will save it here, 49 00:01:58,790 --> 00:02:01,650 ‫press okay so that my API gateway has the power 50 00:02:01,650 --> 00:02:04,060 ‫to invoke this lambda function 51 00:02:04,060 --> 00:02:07,560 ‫and then I will deploy this, so I will deploy this API, 52 00:02:07,560 --> 00:02:10,530 ‫but this time I will deploy it into the canary of prod. 53 00:02:10,530 --> 00:02:13,440 ‫So it says, "You're deploying this API only to the canary" 54 00:02:13,440 --> 00:02:15,530 ‫and then, "To promote it use the promote button." 55 00:02:15,530 --> 00:02:18,040 ‫So I'll deploy this API 56 00:02:18,040 --> 00:02:21,040 ‫and now the canary deployment has been done, 57 00:02:21,040 --> 00:02:24,800 ‫so if I go back to my prod API and refresh this page, 58 00:02:24,800 --> 00:02:26,710 ‫I see, "Hello from V1" right now, 59 00:02:26,710 --> 00:02:28,850 ‫but if I refresh I see, "Hello from V2." 60 00:02:28,850 --> 00:02:32,480 ‫And if I refresh again V1, and again V2, and so on. 61 00:02:32,480 --> 00:02:35,400 ‫So as you can see the more I refresh I see V1 and V2, 62 00:02:35,400 --> 00:02:37,527 ‫50 per see, so 50 percent chance of getting V1 63 00:02:37,527 --> 00:02:38,990 ‫and 50 percent chance of getting V2. 64 00:02:38,990 --> 00:02:41,804 ‫And so that means that my canary is working 65 00:02:41,804 --> 00:02:45,000 ‫and that some users are seeing the version two lambda 66 00:02:45,000 --> 00:02:47,700 ‫and some users are seeing the version one lambda function. 67 00:02:47,700 --> 00:02:49,630 ‫And that's the whole power of canaries. 68 00:02:49,630 --> 00:02:52,650 ‫So then I would ensure my system would work correctly, 69 00:02:52,650 --> 00:02:54,450 ‫would look at the metrics, would look at the logs, 70 00:02:54,450 --> 00:02:57,160 ‫see if I get any errors and if I'm happy 71 00:02:57,160 --> 00:03:00,579 ‫with this new version, then I can promote the canary 72 00:03:00,579 --> 00:03:03,895 ‫and say, "Okay, you want to update the canary deployment, 73 00:03:03,895 --> 00:03:07,170 ‫"the stage variables, and set the canary percentage to zero" 74 00:03:07,170 --> 00:03:10,240 ‫so this would effectively promote my lambda function, 75 00:03:10,240 --> 00:03:12,230 ‫my newer lambda function into the stage. 76 00:03:12,230 --> 00:03:16,808 ‫So now the canary has been promoted and if I refresh now 77 00:03:16,808 --> 00:03:18,920 ‫the only thing I should be seeing is V2, 78 00:03:18,920 --> 00:03:20,260 ‫so yes, I only see version two 79 00:03:20,260 --> 00:03:22,060 ‫because I have promoted my canary. 80 00:03:22,060 --> 00:03:24,150 ‫And that's it this is how canaries work, 81 00:03:24,150 --> 00:03:26,440 ‫it could be quiet complicated to get your head around 82 00:03:26,440 --> 00:03:29,930 ‫the complexity of stage variables, canaries, versions, 83 00:03:29,930 --> 00:03:32,110 ‫aliases, and so on in API gateway 84 00:03:32,110 --> 00:03:34,540 ‫but hopefully that was a good introduction 85 00:03:34,540 --> 00:03:37,470 ‫and the exam will just test you on these concepts 86 00:03:37,470 --> 00:03:39,180 ‫not on their implementations. 87 00:03:39,180 --> 00:03:40,110 ‫So I hope that was helpful 88 00:03:40,110 --> 00:03:42,060 ‫and I will see you in the next lecture.