Hello Internet

In previous chapters, we looked at how to build standalone, event-based Lambda functions. Lambda functions were code pieces living in the cloud that respond to different events, such as a new file in S3 bucket or an SNS notification, such as what we will see in following chapters. However, at this stage, maybe our simplest requirements would be to invoke the lambda function with an HTTP request, thus having a fully serverless REST API.

Thanks to API Gateway, it is possible to create a REST API that responds to HTTP requests. API Gateway replaces servlets, servlet containers, application servers, and basically the HTTP layer. When a request arrives at API Gateway, it decides where to route this request, transforms the input, invokes the "backend", and sends back the response to the client.

API Gateway can proxy to many types of backends, and it can be configured separately by the REST resource and the HTTP method. It can proxy requests to a custom HTTP API, to an AWS API, or-most importantly-to a Lambda function. For example, you might have an on-premise REST API and you can route the users resource of your API to that application, while you can route other requests to lambda functions. You can even proxy to AWS APIs, so you can allow users to upload their pictures to an S3 bucket after authorizing them via another Lambda function. This is one of the examples we will see in this book and you will learn how easy it is to build an image upload service using AWS offerings.

In this chapter, we will introduce API Gateway and connect some Lambda functions to HTTP resources and methods. This chapter is extremely important because we will introduce complicated CloudFormation structures and a lot of new concepts. Additionally, we will cover CloudFront, the CDN solution of AWS. With CloudFront, we will enable some HTTP features such as HTTP/2 or IPv6, which are currently not available for API Gateway out of box.

As for this chapter, we will just cover how to create a REST API using the very simple test function we developed in previous chapters. Throughout the book, we will develop more Lambda functions and REST endpoints. These will extend our API Gateway configuration, but it is important that you understand the basics for now. Also, you will explore how to configure a CDN that can be useful even for classical approaches. At the end of the chapter, we will introduce our second Lambda function, which will authorize API calls.

We will cover the following topics in this chapter: