Skip to content

Commit

Permalink
Merge pull request #533 from wri/api-gateway-relax-quota
Browse files Browse the repository at this point in the history
Api gateway relax quota
  • Loading branch information
solomon-negusse authored Jun 3, 2024
2 parents 885fd15 + b233d13 commit 351ae57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
15 changes: 0 additions & 15 deletions terraform/modules/api_gateway/gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,6 @@ resource "aws_api_gateway_usage_plan" "internal" {
burst_limit = var.api_gateway_usage_plans.internal_apps.burst_limit
rate_limit = var.api_gateway_usage_plans.internal_apps.rate_limit
}

# terraform doesn't expose API Gateway's method level throttling so will do that
# manually and this will stop terraform from destroying the manual changes
# Open PR to add the feature to terraform: https://github.com/hashicorp/terraform-provider-aws/pull/20672
lifecycle {
ignore_changes = all
}
}

resource "aws_api_gateway_usage_plan" "external" {
Expand All @@ -206,14 +199,6 @@ resource "aws_api_gateway_usage_plan" "external" {
burst_limit = var.api_gateway_usage_plans.external_apps.burst_limit
rate_limit = var.api_gateway_usage_plans.external_apps.rate_limit
}

# terraform doesn't expose API Gateway's method level throttling so will do that
# manually and this will stop terraform from destroying the manual changes
# Open PR to add the feature to terraform: https://github.com/hashicorp/terraform-provider-aws/pull/20672
lifecycle {
ignore_changes = all
}

}

resource "aws_api_gateway_deployment" "api_gw_dep" {
Expand Down
4 changes: 2 additions & 2 deletions terraform/modules/api_gateway/gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ variable "api_gateway_usage_plans" {
description = "Throttling limits for API Gateway"
default = {
internal_apps = {
quota_limit = 50000 # per day
quota_limit = 500000 # per day
burst_limit = 1000
rate_limit = 200 # per second
}
external_apps = {
quota_limit = 1000
quota_limit = 10000
burst_limit = 20
rate_limit = 10
}
Expand Down
12 changes: 6 additions & 6 deletions terraform/modules/api_gateway/resource/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ resource "aws_api_gateway_integration" "get_endpoint_integration" {
http_method = aws_api_gateway_method.get_endpoint_method.http_method
type = "MOCK"

passthrough_behavior = "WHEN_NO_MATCH"
request_templates = {
passthrough_behavior = "WHEN_NO_MATCH"
request_templates = {
"application/json" : <<EOT
{'statusCode': 200}
#set($context.responseOverride.header.Access-Control-Allow-Origin = $input.params('origin'))
Expand Down Expand Up @@ -71,7 +71,7 @@ resource "aws_api_gateway_gateway_response" "exceeded_quota" {
response_type = "QUOTA_EXCEEDED"

response_templates = {
"application/json" = "{\"status\":\"failed\",\"message\":\"Exceeded the daily quota for this resource.\"}"
"application/json" = "{\"status\":\"failed\",\"message\":\"Exceeded the daily quota for this resource. Please email us at [email protected] to see if your use case may qualify for higher quota.\"}"
}
}

Expand All @@ -81,13 +81,13 @@ resource "aws_api_gateway_gateway_response" "throttled" {
response_type = "THROTTLED"

response_templates = {
"application/json" = "{\"status\":\"failed\",\"message\":\"Exceeded the rate limit for this resource. Please try again later.\"}"
"application/json" = "{\"status\":\"failed\",\"message\":\"Exceeded the rate limit for this resource. Please try again later. Also email us at [email protected] to see if your use case may qualify for higher rate limit.\"}"
}
}

resource "aws_api_gateway_gateway_response" "integration_timeout" {
rest_api_id = var.rest_api_id
status_code = "504"
rest_api_id = var.rest_api_id
status_code = "504"
response_type = "INTEGRATION_TIMEOUT"

response_templates = {
Expand Down

0 comments on commit 351ae57

Please sign in to comment.