AWS API Gateway Base Path Mapping
This page shows how to write Terraform and CloudFormation for API Gateway Base Path Mapping and write them securely.
aws_api_gateway_base_path_mapping (Terraform)
The Base Path Mapping in API Gateway can be configured in Terraform with the resource name aws_api_gateway_base_path_mapping
. The following sections describe 1 example of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_api_gateway_base_path_mapping" "domain_mapping" {
api_id = var.rest_api_id
domain_name = aws_api_gateway_domain_name.domain.domain_name
stage_name = var.stage_name
Parameters
-
api_id
required - string -
base_path
optional - string -
domain_name
required - string -
id
optional computed - string -
stage_name
optional - string
Explanation in Terraform Registry
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.
Tips: Best Practices for The Other AWS API Gateway Resources
In addition to the aws_api_gateway_method_settings, AWS API Gateway has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_api_gateway_method_settings
Ensure that API Gateway stage-level cache is encrypted
It is better to enable the stage-level cache encryption which reduces the risk of data leakage.
aws_api_gateway_domain_name
Ensure to use modern TLS protocols
It is better to adopt TLS v1.2+.
aws_api_gateway_stage
Ensure to enable access logging of your API Gateway stage (v1)
It is better to enable the access logging of your API Gateway stage (v1).
aws_api_gateway_method
Ensure that your API Gateway method blocks unwanted access
It is better that the API Gateway method does not allow public access.
AWS::ApiGateway::BasePathMapping (CloudFormation)
The BasePathMapping in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::BasePathMapping
. 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
-
BasePath
optional - String -
DomainName
required - String -
RestApiId
optional - String -
Stage
optional - String
Explanation in CloudFormation Registry
The
AWS::ApiGateway::BasePathMapping
resource creates a base path that clients who call your API must use in the invocation URL.
Frequently asked questions
What is AWS API Gateway Base Path Mapping?
AWS API Gateway Base Path Mapping is a resource for API Gateway of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS API Gateway Base Path Mapping?
For Terraform, the cosmic-fusion/cosmic-fusion-api source code example is useful. See the Terraform Example section for further details.