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 that require a
key.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::ApiGateway::ApiKey", "Properties" : { "CustomerId" :String, "Description" :String, "Enabled" :Boolean, "GenerateDistinctId" :Boolean, "Name" :String, "StageKeys" : [StageKey, ...] } }
YAML
Type: AWS::ApiGateway::ApiKey Properties: CustomerId:StringDescription:StringEnabled:BooleanGenerateDistinctId:BooleanName:StringStageKeys: -StageKey-...
Properties
CustomerId-
An AWS Marketplace customer identifier to use when integrating with the AWS SaaS Marketplace.
Required: No
Type: String
Update requires: No interruption
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
GenerateDistinctId-
Specifies whether the key identifier is distinct from the created API key value.
Required: No
Type: Boolean
Update requires: Replacement
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 associate with this API key.
Required: No
Type: List of Amazon API Gateway ApiKey StageKey property types
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.
Examples
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, which would cause the
association to fail
because the deployment and stage wouldn't exist.
JSON
"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
ApiKey: Type: AWS::ApiGateway::ApiKey DependsOn: - "TestAPIDeployment" - "Test" Properties: Name: "TestApiKey" Description: "CloudFormation API Key V1" Enabled: "true" StageKeys: - RestApiId: Ref: "RestApi" StageName: "Test"
The following example creates an API key, and enables you to specify a customer ID and whether to create a distinct ID.
JSON
{ "Parameters": { "apiKeyName": { "Type": "String" }, "customerId": { "Type": "String" }, "generateDistinctId": { "Type": "String" } }, "Resources": { "ApiKey": { "Type": "AWS::ApiGateway::ApiKey", "Properties": { "CustomerId": { "Ref": "customerId" }, "GenerateDistinctId": { "Ref": "generateDistinctId" }, "Name": { "Ref": "apiKeyName" } } } } }
YAML
Parameters: apiKeyName: Type: String customerId: Type: String generateDistinctId: Type: String Resources: ApiKey: Type: AWS::ApiGateway::ApiKey Properties: CustomerId: !Ref customerId GenerateDistinctId: !Ref generateDistinctId Name: !Ref apiKeyName
See Also
-
apikey:create operation in the Amazon API Gateway REST API Reference
