Resource: aws_api_gateway_base_path_mapping

Connects a custom domain name registered via aws_api_gateway_domain_name with a deployed API so that its methods can be called via the custom domain name.

Example Usage

An end-to-end example of a REST API configured with OpenAPI can be found in the /examples/api-gateway-rest-api-openapi directory within the GitHub repository.

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"
}

resource "aws_api_gateway_domain_name" "example" {
  domain_name = "example.com"

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

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

Argument Reference

This resource supports the following arguments:

Attribute Reference

This resource exports no additional attributes.

Import

In Terraform v1.5.0 and later, use an import block to import aws_api_gateway_base_path_mapping using the domain name and base path. For example:

For an empty base_path or, in other words, a root path (/):

import {
  to = aws_api_gateway_base_path_mapping.example
  id = "example.com/"
}

For a non-root base_path:

import {
  to = aws_api_gateway_base_path_mapping.example
  id = "example.com/base-path"
}

Using terraform import, import aws_api_gateway_base_path_mapping using the domain name and base path. For example:

For an empty base_path or, in other words, a root path (/):

% terraform import aws_api_gateway_base_path_mapping.example example.com/

For a non-root base_path:

% terraform import aws_api_gateway_base_path_mapping.example example.com/base-path