» Resource: aws_apigatewayv2_api

Manages an Amazon API Gateway Version 2 API.

» Example Usage

» Basic WebSocket API

resource "aws_apigatewayv2_api" "example" {
  name                       = "example-websocket-api"
  protocol_type              = "WEBSOCKET"
  route_selection_expression = "$request.body.action"

» Basic HTTP API

resource "aws_apigatewayv2_api" "example" {
  name          = "example-http-api"
  protocol_type = "HTTP"

» Argument Reference

The following arguments are supported:

  • name - (Required) The name of the API.
  • protocol_type - (Required) The API protocol. Valid values: HTTP, WEBSOCKET.
  • api_key_selection_expression - (Optional) An API key selection expression. Valid values: $context.authorizer.usageIdentifierKey, $request.header.x-api-key. Defaults to $request.header.x-api-key. Applicable for WebSocket APIs.
  • cors_configuration - (Optional) The cross-origin resource sharing (CORS) configuration. Applicable for HTTP APIs.
  • credentials_arn - (Optional) Part of quick create. Specifies any credentials required for the integration. Applicable for HTTP APIs.
  • description - (Optional) The description of the API.
  • route_key - (Optional) Part of quick create. Specifies any route key. Applicable for HTTP APIs.
  • route_selection_expression - (Optional) The route selection expression for the API. Defaults to $request.method $request.path.
  • tags - (Optional) A map of tags to assign to the API.
  • target - (Optional) Part of quick create. Quick create produces an API with an integration, a default catch-all route, and a default stage which is configured to automatically deploy changes. For HTTP integrations, specify a fully qualified URL. For Lambda integrations, specify a function ARN. The type of the integration will be HTTP_PROXY or AWS_PROXY, respectively. Applicable for HTTP APIs.
  • version - (Optional) A version identifier for the API.

The cors_configuration object supports the following:

  • allow_credentials - (Optional) Whether credentials are included in the CORS request.
  • allow_headers - (Optional) The set of allowed HTTP headers.
  • allow_methods - (Optional) The set of allowed HTTP methods.
  • allow_origins - (Optional) The set of allowed origins.
  • expose_headers - (Optional) The set of exposed HTTP headers.
  • max_age - (Optional) The number of seconds that the browser should cache preflight request results.

» Attribute Reference

In addition to all arguments above, the following attributes are exported:

» Import

aws_apigatewayv2_api can be imported by using the API identifier, e.g.

$ terraform import aws_apigatewayv2_api.example aabbccddee