Resource: aws_apigatewayv2_route

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.

Example Usage

Basic

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"
}

HTTP Proxy Integration

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}"
}

Argument Reference

This resource supports the following arguments:

The request_parameter object supports the following:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

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