Manages an Amazon API Gateway Version 2 route. More information can be found in the Amazon API Gateway Developer Guide for WebSocket and HTTP APIs.
resource "aws_apigatewayv2_api" "example" {
name = "example-websocket-api"
protocol_type = "WEBSOCKET"
route_selection_expression = "$request.body.action"
}
resource "aws_apigatewayv2_route" "example" {
api_id = aws_apigatewayv2_api.example.id
route_key = "$default"
}
resource "aws_apigatewayv2_api" "example" {
name = "example-http-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_integration" "example" {
api_id = aws_apigatewayv2_api.example.id
integration_type = "HTTP_PROXY"
integration_method = "ANY"
integration_uri = "https://example.com/{proxy}"
}
resource "aws_apigatewayv2_route" "example" {
api_id = aws_apigatewayv2_api.example.id
route_key = "ANY /example/{proxy+}"
target = "integrations/${aws_apigatewayv2_integration.example.id}"
}
This resource supports the following arguments:
api_id
- (Required) API identifier.route_key
- (Required) Route key for the route. For HTTP APIs, the route key can be either $default
, or a combination of an HTTP method and resource path, for example, GET /pets
.api_key_required
- (Optional) Boolean whether an API key is required for the route. Defaults to false
. Supported only for WebSocket APIs.authorization_scopes
- (Optional) Authorization scopes supported by this route. The scopes are used with a JWT authorizer to authorize the method invocation.authorization_type
- (Optional) Authorization type for the route.
For WebSocket APIs, valid values are NONE
for open access, AWS_IAM
for using AWS IAM permissions, and CUSTOM
for using a Lambda authorizer.
For HTTP APIs, valid values are NONE
for open access, JWT
for using JSON Web Tokens, AWS_IAM
for using AWS IAM permissions, and CUSTOM
for using a Lambda authorizer.
Defaults to NONE
.authorizer_id
- (Optional) Identifier of the aws_apigatewayv2_authorizer
resource to be associated with this route.model_selection_expression
- (Optional) The model selection expression for the route. Supported only for WebSocket APIs.operation_name
- (Optional) Operation name for the route. Must be between 1 and 64 characters in length.request_models
- (Optional) Request models for the route. Supported only for WebSocket APIs.request_parameter
- (Optional) Request parameters for the route. Supported only for WebSocket APIs.route_response_selection_expression
- (Optional) The route response selection expression for the route. Supported only for WebSocket APIs.target
- (Optional) Target for the route, of the form integrations/
IntegrationID
, where IntegrationID
is the identifier of an aws_apigatewayv2_integration
resource.The request_parameter
object supports the following:
request_parameter_key
- (Required) Request parameter key. This is a request data mapping parameter.required
- (Required) Boolean whether or not the parameter is required.This resource exports the following attributes in addition to the arguments above:
id
- Route identifier.In Terraform v1.5.0 and later, use an import
block to import aws_apigatewayv2_route
using the API identifier and route identifier. For example:
import {
to = aws_apigatewayv2_route.example
id = "aabbccddee/1122334"
}
Using terraform import
, import aws_apigatewayv2_route
using the API identifier and route identifier. For example:
% terraform import aws_apigatewayv2_route.example aabbccddee/1122334