Skip to content

Resource: awsApiGatewayBasePathMapping

Connects a custom domain name registered via awsApiGatewayDomainName 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/apiGatewayRestApiOpenapi directory within the GitHub repository.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsApiGatewayDomainNameExample =
  new aws.apiGatewayDomainName.ApiGatewayDomainName(this, "example", {
    certificateBody: '${file("${path.module}/example.com/example.crt")}',
    certificateChain: '${file("${path.module}/example.com/ca.crt")}',
    certificateName: "example-api",
    certificatePrivateKey: '${file("${path.module}/example.com/example.key")}',
    domainName: "example.com",
  });
const awsApiGatewayStageExample = new aws.apiGatewayStage.ApiGatewayStage(
  this,
  "example_1",
  {
    deploymentId: "${aws_api_gateway_deployment.example.id}",
    restApiId: "${aws_api_gateway_rest_api.example.id}",
    stageName: "example",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayStageExample.overrideLogicalId("example");
const awsApiGatewayBasePathMappingExample =
  new aws.apiGatewayBasePathMapping.ApiGatewayBasePathMapping(
    this,
    "example_2",
    {
      apiId: "${aws_api_gateway_rest_api.example.id}",
      domainName: awsApiGatewayDomainNameExample.domainName,
      stageName: awsApiGatewayStageExample.stageName,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayBasePathMappingExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • domainName - (Required) Already-registered domain name to connect the API to.
  • apiId - (Required) ID of the API to connect.
  • stageName - (Optional) Name of a specific deployment stage to expose at the given path. If omitted, callers may select any stage by including its name as a path element after the base path.
  • basePath - (Optional) Path segment that must be prepended to the path when accessing the API via this mapping. If omitted, the API is exposed at the root of the given domain.

Attributes Reference

No additional attributes are exported.

Import

awsApiGatewayBasePathMapping can be imported by using the domain name and base path, e.g.,

For empty basePath (e.g., root path (/)):

$ terraform import aws_api_gateway_base_path_mapping.example example.com/

Otherwise:

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