• Articles
  • Tutorials
  • Interview Questions

What is Amazon API Gateway?

In this article you will learn about the in-demand service of AWS that is the Amazon API Gateway. First, we will understand what is an API, types of API, API Gateway, then about Amazon API gateway, its need, hands-on tutorial, use cases and finally we will see about the pricing.

Here are various topics covered in this blog on what is Amazon API Gateway in case you want to jump to a section directly.

Do you want to learn more about Amazon Web Services? Watch this complete AWS tutorial course for beginners:

What is an API?

The formal definition for an API goes like this:

An API is a set of definitions and protocols for building and integrating application software. API stands for ‘application programming interface’.

But in simple terms, it is an intermediary between two applications that allows them to communicate with each other. Each time you are using a web browser you are calling an API that helps you to interact with the server where the page that you want resides.

Another real-time example is delivery services that have their own app. Inside that app, they use Google Maps API to pull out a current delivery status for a delivery.

Any website where you make payments at the end includes several payment options like ‘Pay through PayPal’. The website here uses PayPal’s API and allows its users to pay through PayPal. 

Types of API 

The following are the various types of APIs:

HTTP API

It is an application programming interface for a web server or a web browser. It is related to web development, usually limited to a web application’s client-side.

It may be public or private. Private HTTP APIs require an access token.

REST API

It stands for representational state transfer API. Not all HTTP APIs are necessarily REST APIs. These two follow a relation which can be described as: “A REST API is an HTTP API but not all HTTP APIs are REST APIs.”

REST APIs are flexible when compared to HTTP APIs. Here the data is not tied to methods and resources hence these types of data are able to handle multiple types of calls and return different data formats.

WebSocket API

This type of API allows you to create “web sockets” which is capable of bi-directional full-duplex communication over a persistent TCP connection(socket). This API is written in JavaScript.

These are used to build real-time 2-way communication applications, such as chat apps and streaming dashboards.

What is an API Gateway?

An API gateway is like an API management tool that is essentially a computer software that sits between a client and a collection of backend services. It is a single entry point for all the backend APIs and microservices. An API is useless unless it is delivered with consistency. Hence the API Gateway is built to provide security, scalability and high availability. To sum up, the API Gateway takes all the API requests from the client, gauges which services are really required and combines them into a seamless experience for the user. Some of the top API Gateways are Apigee, MuleSoft, AXway and 3scale.

API Gateway

Cloud Computing EPGC IITR iHUB

What is Amazon API Gateway?

As we all know Amazon Web Services is the world’s leading cloud provider and Amazon also provides its own variant of an API Gateway. AWS API Gateway is an AWS service for creating, publishing, maintaining, monitoring REST APIs, HTTP, and WebSocket APIs.

API developers can create APIs that access AWS or other web services, as well as data stored in the AWS Cloud. As an API Gateway API developer, you can create APIs for use in your own client applications.

Working of Amazon API Gateway

API Gateway architecture diagram

Typically, in all architecture that you see with Lambda function, right before the Lambda function where the working code is deployed you would use an AWS API Gateway. So, why should your request go through an Amazon API Gateway? Let us understand about it.

Most applications today are built around REST APIs. So, you have GET, POST, PUT, DELETE requests. You make an API call and get your things done. However, the management of REST API is not easy.

  • You may have to take care of authentication and authorization.
  • You may have to set limits (rate limiting, quotas) for your API consumers.
  • You may have to take care of implementing multiple versions of your API.
  • You would also need to monitor your API calls.
  • To improve your performance you would also want to cache your API requests.

So, how would you maintain and manage all those features? How about a fully managed service with AWS auto-scaling that acts as an abstract layer to your APIs? This is how the Amazon API works. It works as an abstract layer that takes care of all your APIs.

Preparing for interviews? Check out our blog on AWS Questions!

Need for Amazon API Gateway

In enterprises that follow DevOps methodologies, what developers usually do is use already existing microservices to build and deploy apps in a fast-paced, iterative way. These microservices use APIs to communicate with the app. And when this application uses many microservices, many APIs are used for communication between the app and microservices. Managing all these APIs becomes a hassle. This is where the AWS API gateway comes into the picture.

Getting Started with the Amazon API Gateway

To begin, use the AWS Lambda console to create a Lambda function. The API Gateway console is then used to create an HTTP API. Then you call your API.

When you call your HTTP API, API Gateway routes the request to your Lambda function. Lambda executes the Lambda function and responds to API Gateway. You will then receive a response from API Gateway.

API Gateway Steps

Step1: Create a lambda function

Navigate to Lambda under compute services.

1

Click on Create Function

Then type in a function name, in this case, ‘my function’ and let the language be default i.e, node.js 14.x and click on create function.

A lambda function is now created with sample code from AWS in node.js 

Step2: Create an HTTP API

Search for API Gateway service inside the AWS console

Next, we need to create an HTTP API. AWS Lambda also provides REST APIs and WebSocket APIs as well, but for this tutorial creating an HTTP API is best for simplicity.

For integrating the created Lambda function into the API that we are about to create click on ‘Add Integration’

Select Lambda in the Integrations dropdown, then select the lambda function you just created and finally give a name for your HTTP API i.e, ‘my-http-api’

The next step is to review your integration and names that you’ve given and click on create.

Step3: Test your API

Next, you test your API to make sure that it’s working. Use a web browser to invoke your API.

Use this invoke URL and paste it on a web browser. Append the name of your lambda function as shown.

Now, your browser sends a GET request to the  API that you’ve just created.

Verify your API’s response. You should see the text “Hello from Lambda!” in your browser.

Get 100% Hike!

Master Most in Demand Skills Now !

Use cases of Amazon API Gateway 

Vogue

vouge

Vogue is a famous fashion and lifestyle magazine. One of its websites – PhotoVouge uses the Amazon API Gateway. PhotoVouge is a photography website that allows users to upload photos on their site with the chance of being picked up by photography agencies. Every picture that gets uploaded will be carefully reviewed by the editorial team to ensure the highest quality images possible.

The challenge faced by the PhotoVogue website was the high amount of traffic that the website received. The IT infrastructure behind PhotoVouge could not handle the huge amount of traffic and they wanted to give photographers and the editorial staff a better and faster experience.

To overcome these challenges PhotoVogue now uses the Amazon API Gateway in its caching layer for the REST API along with Amazon CloudFront which provides its content delivery network.

FOX Network

fox network

We all know FOX NOW is a well-recognized television network. Fox Digital Consumers Group is a team within FOX Network that handles the streaming of digital content to consumers via the web, mobile and set-top devices. It uses containerized microservices running on AWS to host the website as well as deliver FOX NOW.

FOX Digital Consumer Group has to improve service-request routing and enabling inter-service communication in order to enable a better user experience for its viewers. By using a common API layer powered by Amazon API Gateway and Network Load Balancer, FOX can decouple the frontend from the backend content system completely. And this backend system is hosted on AWS and built by multiple teams using a microservice architecture.

By this FOX Digital Consumer Group was able to provide seamless services to its huge volume of viewers across various platforms.

Master AWS and its concepts by signing up for our AWS course!

AWS API Gateway pricing

You only pay for Amazon API Gateway services only when your APIs are in use. You don’t need to pay minimum fees or upfront payments. The free tier for the Amazon API Gateway service includes one million HTTP API calls, one million REST API calls, one million messages, and 750,000 connection minutes per month for up to 12 months.

After the free tier resources are exhausted, these are the prices for different types of APIs.

HTTP APIs 

REST APIs 

  • Caching 

For better performance and faster execution of the APIs, we can use caching. AWS also provides Caching service in each stage of your API execution. This service is charged on an hourly basis.

Here is the price per hour for various cache memory sizes:

WebSocket APIs

  • Additional charges 

You will be charged extra if the AWS API Gateway service is used in conjunction with other AWS services.

Preparing for AWS Solutions Architect Certification exam? Check out our AWS Course in Bangalore.

Conclusion

We learned that if an application is handling many APIs we need to use a service that enables us to take care of the issues that arise from handling many APIs. This is where the Amazon API Gateway comes in handy. Since this service is used by enterprises like FOX NOW and Vogue it establishes the fact that it is a reliable service. It is also a cost-effective solution to many app problems as the cost for 1 million requests is as low as $1. Lastly, when we use Amazon API Gateway along with other AWS services like AWS Lambda and ECS the application gives a smooth user experience.

Course Schedule

Name Date Details
AWS Certification 20 Apr 2024(Sat-Sun) Weekend Batch
View Details
AWS Certification 27 Apr 2024(Sat-Sun) Weekend Batch
View Details
AWS Certification 04 May 2024(Sat-Sun) Weekend Batch
View Details

Cloud-banner.png