1 00:00:06,690 --> 00:00:10,810 - Now let's review an introduction to Amazon API Gateway. 2 00:00:10,810 --> 00:00:14,960 With Amazon API Gateway, we get a fully-managed service 3 00:00:14,960 --> 00:00:18,080 for creating, publishing, deploying, 4 00:00:18,080 --> 00:00:21,640 and running APIs at any scale. 5 00:00:21,640 --> 00:00:24,080 The service itself will automatically scale 6 00:00:24,080 --> 00:00:27,150 to support the level of requests that are passing through, 7 00:00:27,150 --> 00:00:30,330 and so an API Gateway essentially acts 8 00:00:30,330 --> 00:00:33,070 as a front door to backend services. 9 00:00:33,070 --> 00:00:35,540 We can centrally manage a number of things 10 00:00:35,540 --> 00:00:38,340 at the gateway rather than duplicating 11 00:00:38,340 --> 00:00:42,340 those efforts across various backend services. 12 00:00:42,340 --> 00:00:47,340 And so API Gateway does support Rest and WebSocket APIs. 13 00:00:48,040 --> 00:00:51,250 All we have to do is, within the API Gateway, 14 00:00:51,250 --> 00:00:53,880 we define our resources 15 00:00:53,880 --> 00:00:57,320 and we define methods for those resources 16 00:00:57,320 --> 00:01:00,060 and then we define what backend service 17 00:01:00,060 --> 00:01:02,140 will handle that method. 18 00:01:02,140 --> 00:01:05,850 Now our backend applications can run just about anywhere, 19 00:01:05,850 --> 00:01:10,850 including but not limited to EC2, ECS, Lambda, and so on. 20 00:01:12,560 --> 00:01:15,250 So we have a lot of flexibility, a lot of choices 21 00:01:15,250 --> 00:01:18,970 to where we actually put our backend services, 22 00:01:18,970 --> 00:01:23,020 and in fact, it could be that we have different services 23 00:01:23,020 --> 00:01:26,300 running in different places for different reasons. 24 00:01:26,300 --> 00:01:29,640 And so API Gateway also gives us a number of tools 25 00:01:29,640 --> 00:01:32,930 to centrally manage things like traffic management, 26 00:01:32,930 --> 00:01:35,200 rate limiting, for example. 27 00:01:35,200 --> 00:01:37,270 We also get tools to perform 28 00:01:37,270 --> 00:01:39,280 authentication and authorization. 29 00:01:39,280 --> 00:01:42,610 We could leverage something like Amazon Cognito 30 00:01:42,610 --> 00:01:45,480 if we wanted our users to log in with Facebook, 31 00:01:45,480 --> 00:01:47,840 login with Twitter, and Google, and so on. 32 00:01:47,840 --> 00:01:50,260 We could also write out own custom 33 00:01:50,260 --> 00:01:54,520 authentication and authorization methods in Lambda. 34 00:01:54,520 --> 00:01:56,890 We also have built-in caching 35 00:01:56,890 --> 00:01:59,710 so we don't necessarily need to set-up 36 00:01:59,710 --> 00:02:01,940 a separate cache somewhere else. 37 00:02:01,940 --> 00:02:05,000 We can leverage built-in caching through 38 00:02:05,000 --> 00:02:07,350 the API Gateway service itself. 39 00:02:07,350 --> 00:02:11,980 And then we also have the ability to use API Gateway 40 00:02:11,980 --> 00:02:14,990 as a proxy to other AWS services 41 00:02:14,990 --> 00:02:18,370 such as S3 or Kinesis and more. 42 00:02:18,370 --> 00:02:20,650 So let's take a look at a diagram here. 43 00:02:20,650 --> 00:02:25,140 You'll see that all we have to do is, again, 44 00:02:25,140 --> 00:02:29,090 through the API Gateway service we create a gateway, 45 00:02:29,090 --> 00:02:31,310 and then once we have that gateway, 46 00:02:31,310 --> 00:02:34,030 we simply define, within that, 47 00:02:34,030 --> 00:02:36,470 we simply define our resources 48 00:02:36,470 --> 00:02:40,380 and the various methods underneath those resources. 49 00:02:40,380 --> 00:02:41,213 Right? 50 00:02:41,213 --> 00:02:44,780 And so once we define those, we then define 51 00:02:44,780 --> 00:02:48,990 the various backend services that will handle those methods. 52 00:02:48,990 --> 00:02:53,990 And again, those could be handled by applications 53 00:02:54,150 --> 00:02:57,820 running directly on EC2, and those would be 54 00:02:57,820 --> 00:03:00,210 behind a load balancer. 55 00:03:00,210 --> 00:03:02,920 We could have applications running in Lambda 56 00:03:02,920 --> 00:03:04,800 or functions within Lambda. 57 00:03:04,800 --> 00:03:08,340 So, a pattern here could be that you have 58 00:03:08,340 --> 00:03:10,440 particular resources and methods 59 00:03:10,440 --> 00:03:13,460 that are then passed on to Lambda. 60 00:03:13,460 --> 00:03:16,710 Now, remember that Lambda gives us the ability 61 00:03:16,710 --> 00:03:20,620 to create functions, and we call them functions for a reason 62 00:03:20,620 --> 00:03:24,830 because functions do, each function will do one thing, 63 00:03:24,830 --> 00:03:27,180 one specific kind of work. 64 00:03:27,180 --> 00:03:30,720 Now, technically it would be possible for you 65 00:03:30,720 --> 00:03:35,440 to create one function that handles all of the methods 66 00:03:35,440 --> 00:03:38,300 for a particular resource, but in my experience, 67 00:03:38,300 --> 00:03:42,460 doing that kind of thing actually becomes hard to maintain. 68 00:03:42,460 --> 00:03:44,680 What's more likely that you would do 69 00:03:44,680 --> 00:03:47,980 is create a Lambda function per method, right. 70 00:03:47,980 --> 00:03:50,810 So you imagine all of the restful API methods 71 00:03:50,810 --> 00:03:53,920 that would exist on any particular resource, 72 00:03:53,920 --> 00:03:55,630 you would create a Lambda function 73 00:03:55,630 --> 00:03:58,200 for each one of those methods. 74 00:03:58,200 --> 00:04:01,410 And then we could also use containers 75 00:04:01,410 --> 00:04:04,910 running within Amazon ECS or EKS, 76 00:04:04,910 --> 00:04:07,810 and so again, those containers would also, in that case, 77 00:04:07,810 --> 00:04:11,040 be behind some type of elastic load balancer. 78 00:04:11,040 --> 00:04:14,260 And so these, all of this here, 79 00:04:14,260 --> 00:04:16,900 would be our applications, right. 80 00:04:16,900 --> 00:04:18,850 We would be running our applications, 81 00:04:18,850 --> 00:04:23,230 our custom code, on one of these services, 82 00:04:23,230 --> 00:04:24,450 and like I mentioned earlier, 83 00:04:24,450 --> 00:04:27,770 we can also use API Gateway to act 84 00:04:27,770 --> 00:04:31,900 as a proxy for other services like S3. 85 00:04:31,900 --> 00:04:36,550 We could API Gateway to act as a proxy for Kinesis and more. 86 00:04:36,550 --> 00:04:37,940 We're not limited to those two. 87 00:04:37,940 --> 00:04:41,410 There are other services that we could wire in. 88 00:04:41,410 --> 00:04:45,420 And so the benefit of using an API Gateway 89 00:04:45,420 --> 00:04:47,810 is that we can centralize common things. 90 00:04:47,810 --> 00:04:52,610 Again, we may have each one of these services may require 91 00:04:52,610 --> 00:04:56,230 some type of authentication and authorization, 92 00:04:56,230 --> 00:05:01,230 and we can centralize that here at the API Gateway. 93 00:05:02,560 --> 00:05:04,920 We might want to perform request tracing 94 00:05:04,920 --> 00:05:09,140 and access request logging. 95 00:05:09,140 --> 00:05:12,020 We may want to perform some type of caching, 96 00:05:12,020 --> 00:05:13,480 and so again, a number of things 97 00:05:13,480 --> 00:05:17,090 that we can centralize at the gateway itself. 98 00:05:17,090 --> 00:05:21,560 So if you are planning to build a restful API, 99 00:05:21,560 --> 00:05:26,420 if you are looking to migrate APIs into AWS, 100 00:05:26,420 --> 00:05:30,150 or what I've seen is organizations who are building 101 00:05:30,150 --> 00:05:35,150 new microservices while still relying on legacy monoliths. 102 00:05:35,520 --> 00:05:39,330 And so it could be that you put both of those together 103 00:05:39,330 --> 00:05:43,670 behind one API Gateway, and then as time goes on, 104 00:05:43,670 --> 00:05:48,120 you swap out the monolith for microservices 105 00:05:48,120 --> 00:05:51,130 and then your end users are never the wiser 106 00:05:51,130 --> 00:05:53,920 because they always hit the same end point, right. 107 00:05:53,920 --> 00:05:56,740 So if you're thinking about those kinds of things, 108 00:05:56,740 --> 00:05:58,320 I would highly recommend that you 109 00:05:58,320 --> 00:06:00,703 take a look at Amazon API Gateway.