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
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
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
resource "aws_apigatewayv2_api_mapping" "this" {}
resource "aws_apigatewayv2_route" "this" {}
resource "aws_apigatewayv2_integration" "this" {}
# DynamoDB
resource "aws_dynamodb_table" "this" {}
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
}
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
}
Parameters
-
api_id
required - string -
api_mapping_key
optional - string -
domain_name
required - string -
id
optional computed - string -
stage
required - string
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
-
DomainName
required - String -
Stage
required - String -
ApiMappingKey
optional - String -
ApiId
required - String
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.