- 新しい順
- 投票が多い順
- コメントが多い順
You can achieve this by using a Lambda authorizer. When you do, you have the option to define the API key is retruned from the Lambda function. In there you can translate the token into an API Key. You will need to add the API keys to API Gateway and associate them with usage plans.
Hello, you can use authorizer-sourced API keys [1] to achieve this use case. Unlike reading the API key from the client headers, the authorizer lambda function will perform your custom logic on the Bearer Token and decide if the API key is to be provided or not for the request that ultimately decides if usage plan is applied or not. You can follow below steps for the same:
- Create an API and its required methods, resources and deploy it.
- Create an API key.
- Create a Usage Plan and associate it with the API Stage and the API Key created in step2.
- Navigate to the API settings and change the API key source [2] to “AUTHORIZER”. Scroll down and save the changes.
- Create a Token Based Lambda authorizer whose logic with decide if the request is authenticated (hence, applying the usage plan) and accordingly add the “usageIdentifierKey” parameter in the authorizer returned response. The request is executed only if the usageIdentifierKey is present in the root level of the authorizer returned JSON object [3].
- For the required API methods, configure the method request for Lambda authorizer and API keys.
- Deploy the API again to the same stage as in step1.
- Call the API with the appropriate bearer token and observe the output (“forbidden”/“limit exceeded”/expected output of successful execution).
[2] https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-key-source.html
関連するコンテンツ
- AWS公式更新しました 2年前