Welcome back to BackSpace Academy. In this lecture on the API gateway I'm 1
going to keep it quite brief insofar as the theory behind all this and the reason 2
being is that the the AWS associate level certification doesn't require too 3
much knowledge of the API gateway but you need to understand how it all works 4
and so the best way to do that is to get in get your hands dirty and start using 5
it for some examples. So the AWS API gateway it acts as a secure front door 6
for our applications to access data business logic or functionality from our 7
back-end services. Its serverless, it creates a simple flexible fully managed 8
pay-as-you-go service that handles all aspects of creating and operating a 9
robust API or application programming interface for our application backends 10
so how does this look from a simple example perspective, so I've got a 11
typical example of an architecture where you would use the Amazon gateway and you 12
would use it to access data in for example an RDS instance so some sort of 13
data source, it could be an RDS instance, it could be Amazon s3, it could be 14
whatever but you want to access that and you want to access it through an 15
application programming interface, so what we can do is that we can have a 16
lambda function between the Amazon API gateway and our data source and so the 17
Amazon API gateway, that will trigger when it receives a request for information 18
or requests for data it will trigger that lambda function and that 19
lambda function will go to the data source and it will retrieve that data 20
and then for that data on to the API gateway, now how do we manage requests 21
and how do we make that fit in with route 53 and cloud front and all this 22
stuff that we we love to use, we can use route 53 to set up a domain for our API 23
and so for example there, we could have a API on example.com as our domain name 24
for our API, so requests coming in will be in the format of a HTTP request. 25
That could be a get request or a post request 26
it could be a put, delete, now don't worry too much if you don't understand what 27
I'm talking about as such now, developers will definitely understand what I'm 28
talking about but architects you're probably going to 29
get lost here but just understand that a get request will be getting data, 30
it would be getting information from that data source, a post requests or a put 31
request or a delete request, that will be changing that data generally and so 32
you might be writing to that data you might be deleting and entering that 33
data, and also we have get requests with a query parameter and they look like get 34
with a question mark and then the query parameter after those. Now with post and 35
get requests with a query parameter CloudFront by default bypasses those 36
completely, it doesn't go to a cloud front distribution because it identifies 37
those as being dynamic data and then it shouldn't be playing with. On the other 38
side of it we've got general get requests and they're just getting 39
information from our data source and so a get request will come in to route 53 40
into our cloud front edge location and then it will be forwarded straight down 41
through our cloud front distribution, if our cloud front distribution has that 42
information or that data, it will send it back to through to route 53 to our end 43
user, if it doesn't it will then go to the API gateway to get that information 44
which will then go and trigger that Lander function to get that information 45
from our data source over here in our RDS instance if it is a post or a 46
get I put or delete request we get requests with a query parameter not a 47
general get request that will be bypassed from the CloudFront distribution 48
and will go directly to the Amazon API gateway and again from there the lambda 49
the function will kick in, it will retrieve that data and it will be sent 50
back through to route 53 back to our 51
end-user. The advantage of all this is that we are going to get the best of 52
both worlds we're going to get high speed low latency response from our 53
cloud front distribution for our get requests our dynamically updating data 54
that will be coming from our get request with a question mark and a query 55
parameter those will go directly to our Amazon gateway and they will not be 56
affected by the CloudFront distribution, the same with post put and delete requests, 57
so that's going to give us the best of both World's there and at the same time 58
our API is only transferring the minimum that it needs to. So these HTTP requests 59
that are coming in are very small they're not web pages that contain images 60
and all sorts of stuff they are just simply a query as to what we want to get 61
and then what is returned is the data and nothing else 62
and so that's how you create really high speed access to your data for your 63
applications. The AWS gateway is a great service for developers and I'd strongly 64
recommend that although you don't need to know a lot about it please 65
concentrate on the next two labs because I think that outside of just getting a 66
certification this is one of those services where you could really take 67
advantage of in your own applications outside of getting a certification 68
I'll give you an example of this and this is the example that we're going to go 69
through except without the cloud front in the final lab. So what I've got here 70
is I've got an Amazon s3 bucket that I've set up for website hosting and we 71
know all about that, we've done section two, and I don't need to explain that 72
anymore and again we've got that hosted with cloud front it's going to give us a 73
really good high speed access to our website so now where our end-user is 74
going to go to our website and they're going to get delivered a html5 website 75
with its JavaScript and its CSS and whatever and that's going to be 76
delivered to our end-users compute environments. The advantage of doing that 77
is that we are now are taking advantage of our end-users compute environment we 78
are not we are not paying to do that for the end user. The end user 79
is using their own resources to do that computing that is required which is 80
great. So the downside is that that is going to be a static website and so it's 81
not going to be having a data that is going to be updated regularly without 82
you know uploading a new website API gateway can provide that dynamic 83
component of our static websites and turn our static websites into living 84
dynamic websites. So once our html5 and JavaScript website is set up and it's 85
and it's running on our clients end on our clients computer resources that 86
client can then issue HTTP requests to the API gateway and again if they get 87
requests they will go to a cloud front service, if they're not, if they're a get 88
with a query parameter or their post or the're put or delete requests, they will go 89
directly to the Amazon API gateway. So that provides us with a great way of 90
building really bulletproof high speed applications with low latency with 91
very little cost and with very little effort it's a completely serverless 92
environment. So without any further ado I'm going to finish it up there and 93
we're going to get stuck into creating this sort of an application.