AWS::ApiGateway::ApiKey - AWS CloudFormation

AWS::ApiGateway::ApiKey

The AWS::ApiGateway::ApiKey resource creates a unique key that you can distribute to clients who are executing 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, ... ], "Tags" : [ Tag, ... ], "Value" : String } }

YAML

Type: AWS::ApiGateway::ApiKey Properties: CustomerId: String Description: String Enabled: Boolean GenerateDistinctId: Boolean Name: String StageKeys: - StageKey Tags: - Tag Value: String

Properties

CustomerId

An AWS Marketplace customer identifier, when integrating with the AWS SaaS Marketplace.

Required: No

Type: String

Update requires: No interruption

Description

The description of the ApiKey.

Required: No

Type: String

Update requires: No interruption

Enabled

Specifies whether the ApiKey can be used by callers.

Required: No

Type: Boolean

Update requires: No interruption

GenerateDistinctId

Specifies whether (true) or not (false) the key identifier is distinct from the created API key value. This parameter is deprecated and should not be used.

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

DEPRECATED FOR USAGE PLANS - Specifies stages associated with the API key.

Required: No

Type: Array of StageKey

Update requires: No interruption

Tags

The key-value map of strings. The valid character set is [a-zA-Z+-=._:/]. The tag key can be up to 128 characters and must not start with aws:. The tag value can be up to 256 characters.

Required: No

Type: Array of Tag

Update requires: No interruption

Value

Specifies a value of the API key.

Required: No

Type: String

Update requires: Replacement

Return values

Ref

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

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

Fn::GetAtt

The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.

APIKeyId

The ID for the API key. For example: abc123.

Examples

API Key

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

Customer ID

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