AWS API Gateway V2 API

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

aws_apigatewayv2_api (Terraform)

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

Example Usage from GitHub

apigatewayv2_api_test.tf#L12
resource "aws_apigatewayv2_api" "http" {
  name          = "test-http-api"
  protocol_type = "HTTP"
}

resource "aws_apigatewayv2_api" "websocket" {
apigatewayv2_api_test.tf#L12
resource "aws_apigatewayv2_api" "http" {
  name          = "test-http-api"
  protocol_type = "HTTP"
}

resource "aws_apigatewayv2_api" "websocket" {
api_gateway.tf#L1
resource "aws_apigatewayv2_api" "http-api" {
  name          = "http-api"
  protocol_type = "HTTP"

  tags = {
    project = local.serviceName
main.tf#L1
resource "aws_apigatewayv2_api" "http-api-gateway" {
  name          = var.http_api_gateway_name
  description   = var.http_api_gateway_description
  protocol_type = "HTTP"
main.tf#L1
resource "aws_apigatewayv2_api" "http-api-gateway" {
  name          = var.http_api_gateway_name
  description   = var.http_api_gateway_description
  protocol_type = "HTTP"

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. -> Note: Amazon API Gateway Version 2 resources are used for creating and deploying WebSocket and HTTP APIs. To create and deploy REST APIs, use Amazon API Gateway Version 1 resources.

AWS::ApiGatewayV2::Api (CloudFormation)

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

Example Usage from GitHub

AWS_ApiGatewayV2_ApiMappingResource.schema.json#L15
      "default" : "AWS::ApiGatewayV2::ApiMapping"
    },
    "Properties" : {
      "$ref" : "AWS_ApiGatewayV2_ApiMapping.schema.json"
    }
  }
AWS_ApiGatewayV2_ApiResource.schema.json#L15
      "default" : "AWS::ApiGatewayV2::Api"
    },
    "Properties" : {
      "$ref" : "AWS_ApiGatewayV2_Api.schema.json"
    }
  }

Parameters

Explanation in CloudFormation Registry

The AWS::ApiGatewayV2::Api resource creates an API. WebSocket APIs and HTTP APIs are supported. For more information about WebSocket APIs, see About WebSocket APIs in API Gateway in the API Gateway Developer Guide. For more information about HTTP APIs, see HTTP APIs in the *API Gateway Developer Guide.

Frequently asked questions

What is AWS API Gateway V2 API?

AWS API Gateway V2 API 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?

For Terraform, the gilyas/infracost, infracost/infracost and pacoraml/awsburpreflector source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the shiver-me-timbers/smt-cloudformation-parent and shiver-me-timbers/smt-cloudformation-parent source code examples are useful. See the CloudFormation Example section for further details.