Search code examples
amazon-web-servicesaws-api-gateway

aws usage plan quota based on per user


The thing I am trying to achieve is with the help of usage plan quota, I want to restrict the user API hit.

For Example:- Usage plan quota for API is 5 request per day.

  1. User1 - hit the API for more than 5 times then it gives him limit exceeds the error
  2. User2 - hit the API for more than 5 times and the same.

I am not able to achieve this behaviour, I am able to limit the API request for all user not for a particular user.

Tried to search the web not able to find any article. Another way to achieve the above task are welcomed.

Note :

Dont provide any article from AWS doc.

If you can explain with simple example you are welcome or else dont post any AWS Doc link in answer


Solution

  • After spending my 2 days there are lot of things which I learned along with AWS for the above answer

    1. So if you are a beginner like me whose AWS starting phase consists of API gateway and dynamodb, would like to inform you that almost every button you see in AWS management panel like creating usage plan, creating API key, associating API Key with your plan all these things can be done via AWS SDK and AWS CLI.
    2. AWS SDK is not only used to write a query to extract data from dynamodb or to read file from AWS S3.
    3. Solution for above scenario -
    • When the user is created we create API key specific for that user using AWS APIGateway SDK method name CreateApiKey,you wont find this method in APIGateway2.
    • Once the API Key is created we assign to our usage plan using this method CreateUsagePlanKey
    • By this way we can create multiple API Key per user, how to store and related it solely depend on your logic