AWS API Gateway V2 Domain Name
This page shows how to write Terraform and CloudFormation for API Gateway V2 Domain Name and write them securely.
aws_apigatewayv2_domain_name (Terraform)
The Domain Name in API Gateway V2 can be configured in Terraform with the resource name aws_apigatewayv2_domain_name. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_apigatewayv2_domain_name" "weak_ssl_protocol" {
domain_name = "api.example.com"
domain_name_configuration {
security_policy = "TLS_1_0" # Noncompliant {{Change this configuration to use a stronger protocol.}}
}
}
resource "aws_apigatewayv2_domain_name" "this" {}
resource "aws_apigatewayv2_api_mapping" "this" {}
resource "aws_apigatewayv2_route" "this" {}
resource "aws_apigatewayv2_integration" "this" {}
# DynamoDB
resource "aws_apigatewayv2_domain_name" "domain_name" {
domain_name = var.domain_name
domain_name_configuration {
certificate_arn = var.acm_certificate
endpoint_type = "REGIONAL"
resource "aws_apigatewayv2_domain_name" "subdomain" {
domain_name = local.subdomain_fullname
domain_name_configuration {
certificate_arn = aws_acm_certificate.main_cert.arn
endpoint_type = "REGIONAL"
resource "aws_apigatewayv2_domain_name" "main" {
domain_name = var.domain_name
domain_name_configuration {
certificate_arn = var.certificate_arn
endpoint_type = "REGIONAL"
Parameters
-
api_mapping_selection_expressionoptional computed - string -
arnoptional computed - string -
domain_namerequired - string -
idoptional computed - string -
tagsoptional - map from string to string -
domain_name_configurationlist block-
certificate_arnrequired - string -
endpoint_typerequired - string -
hosted_zone_idoptional computed - string -
security_policyrequired - string -
target_domain_nameoptional computed - string
-
-
mutual_tls_authenticationlist block-
truststore_urirequired - string -
truststore_versionoptional - string
-
-
timeoutssingle block
Explanation in Terraform Registry
Manages an Amazon API Gateway Version 2 domain name. More information can be found in the Amazon API Gateway Developer Guide. -> Note: This resource establishes ownership of and the TLS settings for a particular domain name. An API stage can be associated with the domain name using the
aws_apigatewayv2_api_mappingresource.
AWS::ApiGatewayV2::DomainName (CloudFormation)
The DomainName in ApiGatewayV2 can be configured in CloudFormation with the resource name AWS::ApiGatewayV2::DomainName. 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
-
MutualTlsAuthenticationoptional - MutualTlsAuthentication -
DomainNamerequired - String -
DomainNameConfigurationsoptional - List of DomainNameConfiguration -
Tagsoptional - Json
Explanation in CloudFormation Registry
The
AWS::ApiGatewayV2::DomainNameresource specifies a custom domain name for your API in Amazon API Gateway (API Gateway). You can use a custom domain name to provide a URL that's more intuitive and easier to recall. For more information about using custom domain names, see Set up Custom Domain Name for an API in API Gateway in the API Gateway Developer Guide.
Frequently asked questions
What is AWS API Gateway V2 Domain Name?
AWS API Gateway V2 Domain Name 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 Domain Name?
For Terraform, the SonarSource/sonar-iac, antonbabenko/serverless.tf-playground and mmclsntr/serverless-multi-region-api-sample source code examples are useful. See the Terraform Example section for further details.