This repository contains a sample AWS SAM application which demonstrates how you can accept API Keys in Amazon API Gateway as query string parameters.
It's important to acknowledge that API keys are not a primary authorization mechanism for your APIs. If multiple APIs are associated with a usage plan, a user with a valid API key can access all APIs in that usage plan. We provide numerous options for securing access to your APIs, including resource policies, Lambda authorizers, and Amazon Cognito user pools.
This repository is accompanied by a blog post authored by Ronan Prenty & Zac Burns.
- Clone this repository
git clone https://github.com/aws-samples/amazon-apigateway-accept-apikeys-as-querystring.git
- Navigate locally to the repository using your command line
- Execute the following code:
sam build
// if you encounter Python version issue, use: sam build --use-container
sam deploy --guided
- Client sends HTTP request to API with the API Key in the query string
- Amazon API Gateway sends the request to a REQUEST type custom authorizer
- The custom authorizer function extracts the API Key from the payload. It constructs the response object with the API Key as the value for the
usageIdentifierKey
property - The response gets sent back to API Gateway for validation.
- API Gateway validates the API Key against a usage plan.
- If valid, proceed to the backend.
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.