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 the REST API calls to create and deploy an API,
see restapi:create
and deployment:create
, respectively.
Note
For best practices to consider, see Best practices for API keys and usage plans.
Require an API key on a method
To require an API key on a method, do one of the following:
-
Call
method:put
to create a method. SetapiKeyRequired
totrue
in the request payload. -
Call
method:update
to setapiKeyRequired
totrue
.
Create or import
API keys
To create or import an API key, do one of the following:
-
Call
apikey:create
to create an API key. -
Call
apikey:import
to import an API key from a file. For the file format, see API Gateway API key file format.
You cannot change the value of the new API key. To learn how to configure a usage plan, see Create, configure, and test usage plans using the API Gateway CLI and REST API.