README.md

api-gateway

Creates an API Gateway V2 (HTTP or WebSocket) API with stages, integrations, routes, and a custom domain.

Provisions an HTTP or WebSocket API with CORS configuration, Lambda proxy (or HTTP_PROXY/MOCK) integrations, typed route key mappings, auto-deploying stages with throttle limits and access logging, and an optional custom domain with ACM TLS and API mapping. For REST (v1) APIs, extend with aws_api_gateway_rest_api resources in the calling stack.

Usage

module "api" {
  source  = "hcassc.jfrog.io/iac-terraform-modules-virtual/networking/api-gateway/aws"
  version = "0.1.0"

  name = "my-http-api"

  integrations = {
    lambda = {
      integration_type = "AWS_PROXY"
      integration_uri  = module.lambda.invoke_arns["handler"]
    }
  }

  routes = {
    get_items = {
      route_key       = "GET /items"
      integration_key = "lambda"
    }
  }
}

Requirements

Name Version
terraform ~> 1.5
aws ~> 6.50

Providers

Name Version
aws 6.50.0

Resources

Name Type
aws_apigatewayv2_api.this resource
aws_apigatewayv2_api_mapping.this resource
aws_apigatewayv2_domain_name.this resource
aws_apigatewayv2_integration.this resource
aws_apigatewayv2_route.this resource
aws_apigatewayv2_stage.this resource

Inputs

Name Description Type Default Required
name Name for the API string n/a yes
cors_configuration CORS configuration for HTTP APIs object({ allow_origins = optional(list(string), ["*"]) allow_methods = optional(list(string), ["GET", "POST", "PUT", "DELETE", "OPTIONS"]) allow_headers = optional(list(string), ["Content-Type", "Authorization"]) expose_headers = optional(list(string), []) max_age = optional(number, 86400) allow_credentials = optional(bool, false) }) null no
custom_domain Custom domain name configuration object({ domain_name = string acm_certificate_arn = string endpoint_type = optional(string, "REGIONAL") stage_key = optional(string, "default") api_mapping_key = optional(string, null) }) null no
description API description string "" no
integrations Map of API integrations map(object({ integration_type = string # AWS_PROXY, HTTP_PROXY, MOCK integration_uri = optional(string, null) integration_method = optional(string, "POST") payload_format_version = optional(string, "2.0") timeout_milliseconds = optional(number, 29000) })) {} no
protocol_type API type — HTTP or WEBSOCKET string "HTTP" no
routes Map of API routes map(object({ route_key = string integration_key = optional(string, null) authorization_type = optional(string, "NONE") authorizer_id = optional(string, null) })) {} no
stages Map of API stages to deploy map(object({ name = string auto_deploy = optional(bool, true) throttle_burst_limit = optional(number, 5000) throttle_rate_limit = optional(number, 10000) access_log_arn = optional(string, null) access_log_format = optional(string, "$context.requestId $context.identity.sourceIp $context.httpMethod $context.routeKey $context.status $context.responseLength $context.requestTime") default_route_settings = optional(object({ throttling_burst_limit = optional(number, 5000) throttling_rate_limit = optional(number, 10000) }), null) })) { "default": { "name": "$default" }} no
tags Resource tags to apply to all resources map(string) {} no

Outputs

Name Description
api_endpoint Default API endpoint URL
arn API Gateway V2 API ARN
custom_domain_name Custom domain name API Gateway hostname (null if not configured)
id API Gateway V2 API ID
stage_ids Map of stage logical key to stage ID
stage_invoke_urls Map of stage logical key to invoke URL