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

test_api_gatewayv2_name.tf#L1
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.}}
  }
}
options_for_screenshots.tf#L21
resource "aws_apigatewayv2_domain_name" "this" {}
resource "aws_apigatewayv2_api_mapping" "this" {}
resource "aws_apigatewayv2_route" "this" {}
resource "aws_apigatewayv2_integration" "this" {}

# DynamoDB
custom_domain.tf#L1
resource "aws_apigatewayv2_domain_name" "domain_name" {
  domain_name = var.domain_name

  domain_name_configuration {
    certificate_arn = var.acm_certificate
    endpoint_type   = "REGIONAL"
apigateway.tf#L1
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"
main.tf#L14
resource "aws_apigatewayv2_domain_name" "main" {
  domain_name = var.domain_name

  domain_name_configuration {
    certificate_arn = var.certificate_arn
    endpoint_type   = "REGIONAL"

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 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_mapping resource.

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

Explanation in CloudFormation Registry

The AWS::ApiGatewayV2::DomainName resource 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.