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
resource "aws_apigatewayv2_api" "http" {
name = "test-http-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_api" "websocket" {
resource "aws_apigatewayv2_api" "http" {
name = "test-http-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_api" "websocket" {
resource "aws_apigatewayv2_api" "http-api" {
name = "http-api"
protocol_type = "HTTP"
tags = {
project = local.serviceName
resource "aws_apigatewayv2_api" "http-api-gateway" {
name = var.http_api_gateway_name
description = var.http_api_gateway_description
protocol_type = "HTTP"
resource "aws_apigatewayv2_api" "http-api-gateway" {
name = var.http_api_gateway_name
description = var.http_api_gateway_description
protocol_type = "HTTP"
Parameters
-
api_endpointoptional computed - string -
api_key_selection_expressionoptional - string -
arnoptional computed - string -
bodyoptional - string -
credentials_arnoptional - string -
descriptionoptional - string -
disable_execute_api_endpointoptional - bool -
execution_arnoptional computed - string -
fail_on_warningsoptional - bool -
idoptional computed - string -
namerequired - string -
protocol_typerequired - string -
route_keyoptional - string -
route_selection_expressionoptional - string -
tagsoptional - map from string to string -
targetoptional - string -
versionoptional - string -
cors_configurationlist block-
allow_credentialsoptional - bool -
allow_headersoptional - set of string -
allow_methodsoptional - set of string -
allow_originsoptional - set of string -
expose_headersoptional - set of string -
max_ageoptional - number
-
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
"default" : "AWS::ApiGatewayV2::ApiMapping"
},
"Properties" : {
"$ref" : "AWS_ApiGatewayV2_ApiMapping.schema.json"
}
}
"default" : "AWS::ApiGatewayV2::Api"
},
"Properties" : {
"$ref" : "AWS_ApiGatewayV2_Api.schema.json"
}
}
Parameters
-
RouteSelectionExpressionoptional - String -
BodyS3Locationoptional - BodyS3Location -
Descriptionoptional - String -
BasePathoptional - String -
FailOnWarningsoptional - Boolean -
DisableExecuteApiEndpointoptional - Boolean -
DisableSchemaValidationoptional - Boolean -
Nameoptional - String -
Targetoptional - String -
CredentialsArnoptional - String -
CorsConfigurationoptional - Cors -
Versionoptional - String -
ProtocolTypeoptional - String -
RouteKeyoptional - String -
Bodyoptional - Json -
Tagsoptional - Json -
ApiKeySelectionExpressionoptional - String
Explanation in CloudFormation Registry
The
AWS::ApiGatewayV2::Apiresource 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.