Set up API keys using the API Gateway console - Amazon API Gateway

Set up API keys using the API Gateway console

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. After you create an API key value, it cannot be changed.

For instructions on how to create and deploy an API by using the API Gateway console, see Creating a REST API in Amazon API Gateway and Deploying a REST API in Amazon API Gateway, respectively.

Note

For best practices to consider, see Best practices for API keys and usage plans.

Require API key on a method

The following procedure describes how to configure an API method to require an API key.

Old REST API console
Note

We've redesigned the API Gateway console. On 30th October 2023, the old console will no longer be available.

To configure an API method to require an API key
  1. Sign in to the AWS Management Console and open the API Gateway console at https://console.aws.amazon.com/apigateway/.

  2. Choose a REST API.

  3. In the API Gateway main navigation pane, choose Resources.

  4. Under Resources, create a new method or choose an existing one.

  5. Choose Method Request.

  6. Under the Settings section, choose true for API Key Required.

  7. Select the checkmark icon to save the settings.

  8. Deploy or redeploy the API for the requirement to take effect.

If the API Key Required option is set to false and you don't execute the previous steps, any API key that's associated with an API stage isn't used for the method.

New REST API console
To configure an API method to require an API key
  1. Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.

  2. Choose a REST API.

  3. In the API Gateway main navigation pane, choose Resources.

  4. Under Resources, create a new method or choose an existing one.

  5. On the Method request tab, under Method request settings, choose Edit.

  6. Select API key required.

  7. Choose Save.

  8. Deploy or redeploy the API for the requirement to take effect.

If the API key required option is set to false and you don't execute the previous steps, any API key that's associated with an API stage isn't used for the method.

Create an API key

If you've already created or imported API keys for use with usage plans, you can skip this and the next procedure.

Old REST API console
Note

We've redesigned the API Gateway console. On 30th October 2023, the old console will no longer be available.

To create an API key
  1. Sign in to the AWS Management Console and open the API Gateway console at https://console.aws.amazon.com/apigateway/.

  2. Choose a REST API.

  3. In the API Gateway main navigation pane, choose API Keys.

  4. From the Actions drop-down menu, choose Create API key.

    
                        Create API keys for usage plans
  5. In Create API Key, do the following:

    1. Enter an API key name (for example, MyFirstKey) in the Name input field.

    2. Choose Auto Generate to have API Gateway generate the key value, or choose Custom to enter the key manually.

    3. Choose Save.

    
                        Create API keys for usage plans
  6. Repeat the preceding steps to create more API keys, if needed.

New REST API console
To create an API key
  1. Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.

  2. Choose a REST API.

  3. In the API Gateway main navigation pane, choose API keys.

  4. Choose Create API key.

    
                      Create API keys for usage plans
  5. For Name, enter a name.

  6. (Optional) For Description, enter a description.

  7. For API key, choose Auto generate to have API Gateway generate the key value, or choose Custom to create your own key value.

  8. Choose Save.

Import API keys

The following procedure describes how to import API keys to use with usage plans.

Old REST API console
Note

We've redesigned the API Gateway console. On 30th October 2023, the old console will no longer be available.

To import API keys
  1. Sign in to the AWS Management Console and open the API Gateway console at https://console.aws.amazon.com/apigateway/.

  2. Choose a REST API.

  3. In the main navigation pane, choose API Keys.

  4. From the Actions drop-down menu, choose Import API keys.

  5. To load a comma-separated key file, choose Select CSV File. You can also enter the keys manually. For information about the file format, see API Gateway API key file format.

    
                        API usage plan entities
  6. 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.

  7. To start importing the selected API keys, choose Import.

Now that you've set up the API key, you can proceed to create and use a usage plan.

New REST API console
To import API keys
  1. Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.

  2. Choose a REST API.

  3. In the main navigation pane, choose API keys.

  4. Choose the Actions dropdown menu, and then choose Import API keys.

  5. To load a comma-separated key file, choose Choose file. You can also enter the keys in the text editor. For information about the file format, see API Gateway API key file format.

  6. 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 warning.

  7. Choose Import to import your API keys.