To set up API keys, do the following:
- Configure API methods to require an API key.
- Create or import an API key for the API in a region.
Before setting up API keys, you must have created an API and deployed it to a stage.
The following procedure describes how to configure an API method to require an API key.
To configure an API method to require an API key
Sign in to the AWS Management Console and open the API Gateway console at
https://console.aws.amazon.com/apigateway/.
In the API Gateway main navigation pane, choose Resources.
Under Resources, create a new method or choose an existing one.
Choose Method Request.
Under the Authorization Settings section, choose true for API Key Required.
Select the checkmark icon to save the settings.
Deploy or redeploy the API for the requirement to take effect.
If you've already created or imported API keys for use with usage plans, you can skip this and the next procedure.
To create an API key
Sign in to the AWS Management Console and open the API Gateway console at
https://console.aws.amazon.com/apigateway/.
In the API Gateway main navigation pane, choose API Keys.
From the Actions drop-down menu, choose Create API key.
In Create API Key, do the following:
Type an API key name (for example, MyFirstKey) in the Name input field.
Choose Auto Generate to have API Gateway generate the key value, or choose Custom to enter the key manually.
Choose Save.
Repeat the preceding steps to create more API keys, if needed.
To import API keys
In the main navigation pane, choose API Keys.
From the Actions drop-down menu, choose Import API keys.
To load a comma-separated key file, choose Select CSV File. You can also type the keys manually. For information about the file format, see API Gateway API Key File Format.
Choose Fail on warnings to stop the import when there's an error, or choose Ignore warnings to continue to import valid key entries when there's an error.
To start importing the selected API keys, choose Import.