API Gateway

API Gateway
March 8, 2021

AWS API Gateway helps us to develop RESTful APIs. In some cases, especially for a B2B business, sometimes we need to expose the APIs to a few customers and restrict them on the number or the rate of API calls.

Usage plans help you to define maximum request quotas and manage request rates while sharing your API with others. API Gateway allows us to create API Keys for each of the customers.

By using Usage Plans, you can control the 3 aspects of accessing an API:

  1. Quota
  2. Throttling
  3. API/Stage that can be accessed

Create a usage plan

  1. Go to the API Gateway console and go to Usage Plans on the left side pane.
  2. Enter the Usage Plan name, throttling rate, and quota you want to set on the API, and click Next.
AWS API gateway
AWS API gateway

  1. In the next window, Associated API Stages, select the API from the drop-down and then select the corresponding stage on which you want to apply the usage plan. Click on Next.
  2. Now comes the API Keys part. Create a new API Key. Give the Customer name, and you can select Auto Generate option or provide your Custom Key. Save it.
Creating new API key

As we have configured the usage plan with an API Key, it will start tracking the number of calls if the customer makes the call using the API Key. You can see the usage by going to the plan, the API Keys tab, and clicking Usage.

To complete the configuration, go to the API to which you have applied the Usage plan.

Under Method Execution, set API Key Required to true so that API can’t be invoked without the key.

Do not forget to deploy the API after making the changes.

configured the usage plan with an API Key

When calling the API, the person needs to give the API key in the x-API-key  header, and the usage can be tracked and limited.

Thus, Usage Plans help the business track the customer’s API call, which can be part of different plans. Also, the end customer can be billed based on the usage of the APIs. You can also control access to the API and its resources and allow special grants to users as needed.

Written by – Atin Mittal

Cloud Computing Insights and Resources

Cloud Consulting

6 Reasons to Collaborate with a Cloud Consulting Firm in 2024

The technology landscape keeps evolving, without a break, and the shift towards cloud solutions is undeniable. Companies are increasingly embracing […]

cloud computing

10 Secrets of Optimum Utilization of Clouds 

Cloud computing has emerged as a significant trend in recent years, transforming how businesses operate and delivering a range of […]

AWS migration

An Introduction to AWS’ Migration Acceleration Program

What is AWS MAP?  The Migration Acceleration Program (MAP) stands as an exclusive offering from Amazon Web Services (AWS), available […]