This template connects a custom domain name to a deployed API Gateway, allowing API methods to be accessed via the custom domain.

Terraform Template

resource "aws_api_gateway_base_path_mapping" "example" {
  api_id = "aws_api_gateway_rest_api.example.id"
  domain_name = aws_api_gateway_domain_name.example.domain_name
  stage_name = aws_api_gateway_stage.example.stage_name
}

resource "aws_api_gateway_domain_name" "example" {
  certificate_body = file("${path.module}/example.com/example.crt")
  certificate_chain = file("${path.module}/example.com/ca.crt")
  certificate_name = "example-api"
  certificate_private_key = file("${path.module}/example.com/example.key")
  domain_name = "example.com"
}

resource "aws_api_gateway_stage" "example" {
  deployment_id = "aws_api_gateway_deployment.example.id"
  rest_api_id = "aws_api_gateway_rest_api.example.id"
  stage_name = "example"
}