Most applications will require a way to store data that persists between sessions. When the user starts the application, we need a way to retrieve the latest data. The way the client interacts with the application is called the Application Programming Interface, or API.
To build an API, we can use two services provided by Amazon Web Services, AWS Lambda and API Gateway.
Lambda was the first mainstream Function-as-a-Service (FaaS) platform. FaaS allows developers to build small pieces of functionality without having to worry about setting up infrastructure or scaling to meet demand.
In jargon speak, AWS Lambda is a managed, stateless, compute container. In layman terms, this means AWS Lambda only runs your code when an event it’s tied to fires. The events can be anything from a request from a web page to a new file being stored in Amazons S3 file storage.
Lambda functions are charged on a GB-s (Gigabit-seconds). This means it’s based on the amount of memory times the number of seconds it ran. The expectation is that each lambda will only execute for a few hundred milliseconds at most. It’s possible to let one execute for multiple seconds, but this starts to increase cost significantly, especially if it can be kicked off multiple times simultaneously.
Lambda functions are great on their own. They can be registered to respond to a wide variety of events internal to AWS. However, we also need a way to trigger them from our client applications. This is where the API Gateway comes in.
API Gateway is an AWS service that exposes a REST style API to the world. With it, we can accept requests from any client that knows how to send an HTTP request. It’s essentially the ‘Front-door’ of our application.
We can use API Gateway to interact with our Lambdas. But, we could also use it as the gatekeeper for more traditional web services running on EC2. API Gateway allows us to control access through authentication and tokens so we can lock down our application security.
We can build fully featured and robust APIs using these two technologies. We don’t need to host a large fleet of servers to expose our application to the world. Instead we can use Serverless to allow us to scale at whatever pace we need to.