diff --git a/modules/api_gateway/main.tf b/modules/api_gateway/main.tf new file mode 100644 index 00000000..974da623 --- /dev/null +++ b/modules/api_gateway/main.tf @@ -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 +}