AWS API Gateway Usage Plan
This page shows how to write Terraform and CloudFormation for API Gateway Usage Plan and write them securely.
aws_api_gateway_usage_plan (Terraform)
The Usage Plan in API Gateway can be configured in Terraform with the resource name aws_api_gateway_usage_plan
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_api_gateway_usage_plan" "demo_usage_plan" {
name = "demo_usage_plan"
api_stages {
api_id = aws_api_gateway_rest_api.rest.id
stage = aws_api_gateway_deployment.rest_deploy.stage_name
resource "aws_api_gateway_usage_plan" "usage_plan" {
name = var.name
description = "Api Usage Plan"
api_stages {
api_id = aws_api_gateway_rest_api.api.id
resource "aws_api_gateway_usage_plan" "usage_plan" {
name = var.usage_plan_name
api_stages {
api_id = var.rest_api_id
stage = var.rest_api_deployment_stage_name
Parameters
-
arn
optional computed - string -
description
optional - string -
id
optional computed - string -
name
required - string -
product_code
optional - string -
tags
optional - map from string to string -
api_stages
set block -
quota_settings
list block -
throttle_settings
list block-
burst_limit
optional - number -
rate_limit
optional - number
-
Explanation in Terraform Registry
Provides an API Gateway Usage Plan.
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::UsagePlan (CloudFormation)
The UsagePlan in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::UsagePlan
. 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
-
ApiStages
optional - List of ApiStage -
Description
optional - String -
Quota
optional - QuotaSettings -
Tags
optional - List of Tag -
Throttle
optional - ThrottleSettings -
UsagePlanName
optional - String
Explanation in CloudFormation Registry
The
AWS::ApiGateway::UsagePlan
resource creates a usage plan for deployed APIs. A usage plan enforces throttling and quota limits on individual client API keys. For more information, see Creating and Using API Usage Plans in Amazon API Gateway in the API Gateway Developer Guide.
Frequently asked questions
What is AWS API Gateway Usage Plan?
AWS API Gateway Usage Plan 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 Usage Plan?
For Terraform, the for-good/isgood-api, leonardosmartins/version-control-deployments and vgulkevic/Assets-Wallet source code examples are useful. See the Terraform Example section for further details.