Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api gateway relax quota #533

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it's not possible to add daily quotas at method level so won't be setting anything manually that necessitated this.. and there's terraform way to do that now in case we need 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
Loading