Skip to content

Commit

Permalink
[CT-430] Add api gateway: Amplitude proxy (#63)
Browse files Browse the repository at this point in the history
* Add api gateway

* lint
  • Loading branch information
jiajames authored Feb 7, 2024
1 parent ab28d27 commit f3b4fdf
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions modules/api_gateway/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
terraform {
cloud {
organization = "dydxprotocol"

workspaces {
tags = ["api-gateway"]
}
}

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}

required_version = "~> 1.3.2"
}

provider "aws" {
region = "ap-northeast-1"
}

resource "aws_apigatewayv2_api" "ApiGatewayV2Api" {
name = "dydx-amplitude-proxy"
api_key_selection_expression = "$request.header.x-api-key"
protocol_type = "HTTP"
route_selection_expression = "$request.method $request.path"

cors_configuration {
allow_credentials = false
allow_headers = [
"*"
]
allow_methods = [
"*"
]
allow_origins = [
"*"
]
expose_headers = [
"*"
]
max_age = 0
}

tags = {}
}

resource "aws_apigatewayv2_stage" "ApiGatewayV2Stage" {
name = "proxy-main"
api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id
tags = {}

default_route_settings {
detailed_metrics_enabled = false
throttling_burst_limit = 5000
throttling_rate_limit = 10000
}

deployment_id = aws_apigatewayv2_deployment.deployment-main.id
}

resource "aws_apigatewayv2_route" "ApiGatewayV2Route" {
api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id
api_key_required = false
authorization_type = "NONE"
route_key = "ANY /2/httpapi"

target = "integrations/${aws_apigatewayv2_integration.ApiGatewayV2Integration.id}"
}

resource "aws_apigatewayv2_integration" "ApiGatewayV2Integration" {
api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id
connection_type = "INTERNET"
integration_method = "ANY"
integration_type = "HTTP_PROXY"
integration_uri = "https://api2.amplitude.com/2/httpapi"
timeout_milliseconds = 30000
payload_format_version = "1.0"
}

resource "aws_apigatewayv2_deployment" "deployment-main" {
depends_on = [aws_apigatewayv2_route.ApiGatewayV2Route]
api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id
}

0 comments on commit f3b4fdf

Please sign in to comment.