Use an API Key in API Gateway
You can use an API key in API Gateway to identify apps calling the API and control API access based on the API key. You can use an API key to control how an API is used. For example, you can generate an API key and give it to specific app developers to make the API available for their app users. When an API key is enabled, API calls must contain the specified key, as the value of the
x-api-key header of the requests. Requests without the matching API key will then be rejected. API keys are useful to control that an API is used as expected and curtail abusive uses by changing the API keys. They should not be treated as a security mechanism for controlling access to an API.
Use an API Key with the API Gateway Console
To enable an API key with the API Gateway console, follow these instructions:
Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.
Choose the GET method under a resource of your choosing.
Choose the Method Request box
If API Key Required is set to false, choose the pencil icon next to it. From the drop-down menu list, choose true. Finally, choose the check-mark icon to save the setting.
NoteThe steps above configures the API Gateway to enforce using API key. Otherwise, the API key created following the instructions below will not be used.
In the secondary navigation bar, in the first list next to the console home button, choose API Keys.
Choose Create API Key.
For Name, type a name for the API key entry.
(Optional) For Description, type a description for the API key entry.
To enable the API key, select Enabled.
Choose Save. Make a note of the key displayed in API key.
For API Stage Association, for Select API, choose the name of the API.
For Select stage, choose the name of the stage.
Choose Add, and then choose Save.
Deploy or redeploy the API for the effect to take place.
Callers must now add to each call a custom header named
x-api-key, along with the value of the API key. For example, if the API key value is
bkayZOMvuy8aZOhIgxq94K9Oe7Y70Hw55, the custom header would be as follows:
In addition to, or instead of, enabling an API key, you can restrict access to certain IAM users only. For instructions, see Configure How a User Calls an API Method.