Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::ApiGateway::ApiKey

The AWS::ApiGateway::ApiKey resource creates a unique key that you can distribute to clients who are executing Amazon API Gateway (API Gateway) Method resources that require an API key. To specify which API key clients must use, map the API key with the RestApi and Stage resources that include the methods requiring a key.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

Copy
{ "Type" : "AWS::ApiGateway::ApiKey", "Properties" : { "Description" : String, "Enabled" : Boolean, "Name" : String, "StageKeys" : [ StageKey, ... ] } }

YAML

Copy
Type: "AWS::ApiGateway::ApiKey" Properties: Description: String Enabled: Boolean Name: String StageKeys: - StageKey - ...

Properties

Description

A description of the purpose of the API key.

Required: No

Type: String

Update requires: No interruption

Enabled

Indicates whether the API key can be used by clients.

Required: No

Type: Boolean

Update requires: No interruption

Name

A name for the API key. If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the API key name. For more information, see Name Type.

Important

If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.

Required: No

Type: String

Update requires: Replacement

StageKeys

A list of stages to associated with this API key.

Required: No

Type: List of Amazon API Gateway ApiKey StageKey

Update requires: No interruption

Return Value

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the API key ID, such as m2m1k7sybf.

For more information about using the Ref function, see Ref.

Example

The following example creates an API key and associates it with the Test stage of the TestAPIDeployment deployment. To ensure that AWS CloudFormation creates the stage and deployment (which are declared elsewhere in the same template) before the API key, the example adds an explicit dependency on the deployment and stage. Without this dependency, AWS CloudFormation might create the API key first, causing the association to fail because the deployment and stage wouldn't exist.

JSON

Copy
"ApiKey": { "Type": "AWS::ApiGateway::ApiKey", "DependsOn": ["TestAPIDeployment", "Test"], "Properties": { "Name": "TestApiKey", "Description": "CloudFormation API Key V1", "Enabled": "true", "StageKeys": [{ "RestApiId": { "Ref": "RestApi" }, "StageName": "Test" }] } }

YAML

Copy
ApiKey: Type: "AWS::ApiGateway::ApiKey" DependsOn: - "TestAPIDeployment" - "Test" Properties: Name: "TestApiKey" Description: "CloudFormation API Key V1" Enabled: "true" StageKeys: - RestApiId: Ref: "RestApi" StageName: "Test"