AWS API Gateway API Key
This page shows how to write Terraform and CloudFormation for API Gateway API Key and write them securely.
aws_api_gateway_api_key (Terraform)
The API Key in API Gateway can be configured in Terraform with the resource name aws_api_gateway_api_key
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_api_gateway_api_key" "foo" {
name = "foo"
description = "Foo Api Key"
enabled = false
}
resource "aws_api_gateway_api_key" "dummy" {
# Only deploy the dummy client if it's a non-production environment...
count = lower(terraform.workspace) != "prod" ? 1 : 0
name = "dummy"
resource "aws_api_gateway_api_key" "temp_key" {
name = var.api_key_name
}
resource "aws_api_gateway_usage_plan_key" "main" {
key_id = aws_api_gateway_api_key.temp_key.id
Parameters
-
arn
optional computed - string -
created_date
optional computed - string -
description
optional - string -
enabled
optional - bool -
id
optional computed - string -
last_updated_date
optional computed - string -
name
required - string -
tags
optional - map from string to string -
value
optional computed - string
Explanation in Terraform Registry
Provides an API Gateway API Key.
NOTE: Since the API Gateway usage plans feature was launched on August 11, 2016, usage plans are now required to associate an API key with an API stage.
Tips: Best Practices for The Other AWS API Gateway Resources
In addition to the aws_api_gateway_method_settings, AWS API Gateway has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_api_gateway_method_settings
Ensure that API Gateway stage-level cache is encrypted
It is better to enable the stage-level cache encryption which reduces the risk of data leakage.
aws_api_gateway_domain_name
Ensure to use modern TLS protocols
It is better to adopt TLS v1.2+.
aws_api_gateway_stage
Ensure to enable access logging of your API Gateway stage (v1)
It is better to enable the access logging of your API Gateway stage (v1).
aws_api_gateway_method
Ensure that your API Gateway method blocks unwanted access
It is better that the API Gateway method does not allow public access.
AWS::ApiGateway::ApiKey (CloudFormation)
The ApiKey in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::ApiKey
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
CustomerId
optional - String -
Description
optional - String -
Enabled
optional - Boolean -
GenerateDistinctId
optional - Boolean -
Name
optional - String -
StageKeys
optional - List of StageKey -
Tags
optional - List of Tag -
Value
optional - String
Explanation in CloudFormation Registry
The
AWS::ApiGateway::ApiKey
resource creates a unique key that you can distribute to clients who are executing API GatewayMethod
resources that require an API key. To specify which API key clients must use, map the API key with theRestApi
andStage
resources that include the methods that require a key.
Frequently asked questions
What is AWS API Gateway API Key?
AWS API Gateway API Key is a resource for API Gateway of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS API Gateway API Key?
For Terraform, the cloudskiff/driftctl, wellcomecollection/identity and vgulkevic/Assets-Wallet source code examples are useful. See the Terraform Example section for further details.