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_endpoint
optional computed - string -
api_key_selection_expression
optional - string -
arn
optional computed - string -
body
optional - string -
credentials_arn
optional - string -
description
optional - string -
disable_execute_api_endpoint
optional - bool -
execution_arn
optional computed - string -
fail_on_warnings
optional - bool -
id
optional computed - string -
name
required - string -
protocol_type
required - string -
route_key
optional - string -
route_selection_expression
optional - string -
tags
optional - map from string to string -
target
optional - string -
version
optional - string -
cors_configuration
list block-
allow_credentials
optional - bool -
allow_headers
optional - set of string -
allow_methods
optional - set of string -
allow_origins
optional - set of string -
expose_headers
optional - set of string -
max_age
optional - 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
-
RouteSelectionExpression
optional - String -
BodyS3Location
optional - BodyS3Location -
Description
optional - String -
BasePath
optional - String -
FailOnWarnings
optional - Boolean -
DisableExecuteApiEndpoint
optional - Boolean -
DisableSchemaValidation
optional - Boolean -
Name
optional - String -
Target
optional - String -
CredentialsArn
optional - String -
CorsConfiguration
optional - Cors -
Version
optional - String -
ProtocolType
optional - String -
RouteKey
optional - String -
Body
optional - Json -
Tags
optional - Json -
ApiKeySelectionExpression
optional - String
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.