Check out a free preview of the full Build Go Apps That Scale on AWS course

The "AWS API Gateway" Lesson is part of the full, Build Go Apps That Scale on AWS course featured in this preview video. Here's what you'd learn in this lesson:

Melkey introduces the AWS API Gateway. It's a fully managed service that makes it easy to create, publish, maintain, monitor, and secure APIs at scale. A gateway is like a front door for an application to access backend services.


Transcript from the "AWS API Gateway" Lesson

>> Before going into any further, I wanna introduce the third piece of our infrastructure, the AWS API Gateway. So maybe some of you people are the most lambdas, DynamoDB, maybe someone's the most API Gateway. I think this one doesn't get as much attention, maybe. Maybe it's kind of under the hood, but it plays a vital role in everything that we're building today.

I'm gonna read the definition, the textbook definition, a fully managed service that makes it easy for developers to create, publish, maintain, monitor and secure API's at any scale. Okay, a bunch of great words. But what I enjoy is actually the access data, business logic, or functionality from backend services.

That's a definition I think it's gonna apply mostly to us. The way we're gonna use our AWS API Gateway is almost like a router, okay? And why do I bring this up? Why does it matter? Because if you look back and we go to our main.go, there's a clear problem here.

Can anyone tell me what that problem is? It's on this line.
>> Are you registering the user anytime?
>> No, that's not a problem. I hope that's not a problem. But actually, you're right, because every time we invoke the function, that's the only thing we're doing, is just registering the user.

We have no flexibility. What if we make a login handler? We can't put that in, right? Because we have to either take out our registered user handler and put in the new login user handler, or we have to choose between one or the other, right? And there's different ways you can maybe, I don't know.

Find a way like a hacky fix to make it work, but this is where the AWS Gateway gives us flexibility to add different functionalities to a single lambda, right? And this is an architecture decision, you can have different decisions where instead of having one lambda that has a capability of running three different functions.

You'd have one lambda, bind it to one function and deploy each one. That's totally fair. The Code for that is you have to kind of tell each lambda how to communicate with respect to each other. Like all these lambdas, that can get kind of messy. I've personally liked for something simple like a CRUD app, just to have one lambda that can execute a bunch of different things depending on how it's invoked.

Registering a user, give me the register user function. Logging a user, give me the logging user function, right? I don't really see the core argument to have all these different lambdas doing something that could be contained. But, again, pros and cons to every kind of decision and architecture you want to make.

And one more thing on the API Gateway is that, it also adds and acts like a filter for us. It adds like a layer of security, because this is where we're gonna process requests. And this is where we can basically tell someone or a requester, okay? No, you don't have the right header I expect.

Or no, you're from a different region, or etc. Like I do not want you to go into the back-end. I don't want this request to have any sort of ability to invoke the back-end logic, and this is what the API Gateway can do for us. So that's how we're gonna use it.

We're gonna make it act as like a bit of a security layer, very, very minimal security if I'm being honest, but mostly gonna be acting as a router for us. And again, as with any of these infrastructures developed by a AWS, the use case is massive. There's so many things you can go with it.

There's so many things you can run with it. And this is just, honestly, the tip of the iceberg just to get our dipper toes in the AWS lake if you will.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now