AWS API Gateway V2 API Mapping

This page shows how to write Terraform and CloudFormation for API Gateway V2 API Mapping and write them securely.

aws_apigatewayv2_api_mapping (Terraform)

The API Mapping in API Gateway V2 can be configured in Terraform with the resource name aws_apigatewayv2_api_mapping. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

microservices.tf#L6
resource "aws_apigatewayv2_api_mapping" "stateless_microservices" {
  count           = length(var.http_apis)
  stage           = var.http_apis[count.index].stage
  api_id          = var.http_apis[count.index].id
  api_mapping_key = var.http_apis[count.index].key
  domain_name     = aws_apigatewayv2_domain_name.stateless.domain_name
microservices.tf#L6
resource "aws_apigatewayv2_api_mapping" "stateless_microservices" {
  count           = length(var.http_apis)
  stage           = var.http_apis[count.index].stage
  api_id          = var.http_apis[count.index].id
  api_mapping_key = var.http_apis[count.index].key
  domain_name     = aws_apigatewayv2_domain_name.stateless.domain_name
options_for_screenshots.tf#L22
resource "aws_apigatewayv2_api_mapping" "this" {}
resource "aws_apigatewayv2_route" "this" {}
resource "aws_apigatewayv2_integration" "this" {}

# DynamoDB
resource "aws_dynamodb_table" "this" {}
custom_domain.tf#L11
resource "aws_apigatewayv2_api_mapping" "api_mapping" {
  api_id      = var.api_id
  domain_name = aws_apigatewayv2_domain_name.domain_name.id
  stage       = var.api_stage
}
main.tf#L17
resource "aws_apigatewayv2_api_mapping" "custom_domain" {
  api_id          = var.api_gateway_id
  domain_name     = var.api_gateway_domain_name_id
  stage           = aws_apigatewayv2_stage.stage.id
  api_mapping_key = var.name
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages an Amazon API Gateway Version 2 API mapping. More information can be found in the Amazon API Gateway Developer Guide.

AWS::ApiGatewayV2::ApiMapping (CloudFormation)

The ApiMapping in ApiGatewayV2 can be configured in CloudFormation with the resource name AWS::ApiGatewayV2::ApiMapping. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

Explanation in CloudFormation Registry

The AWS::ApiGatewayV2::ApiMapping resource contains an API mapping. An API mapping relates a path of your custom domain name to a stage of your API. A custom domain name can have multiple API mappings, but the paths can't overlap. A custom domain can map only to APIs of the same protocol type. For more information, see CreateApiMapping in the Amazon API Gateway V2 API Reference.

Frequently asked questions

What is AWS API Gateway V2 API Mapping?

AWS API Gateway V2 API Mapping is a resource for API Gateway V2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS API Gateway V2 API Mapping?

For Terraform, the obytes/terraform-aws-gato, obytes/terraform-aws-gato and antonbabenko/serverless.tf-playground source code examples are useful. See the Terraform Example section for further details.