I have an AWS API Gateway (REST API) which is deployed through Terraform like that:
locals {
api = templatefile("${path.module}/backend-api/api.json", {
service-user-management = aws_lambda_function.user-management.invoke_arn
})
}
resource "aws_api_gateway_rest_api" "backend" {
name = "backend-api"
description = "Backend API"
body = local.api
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_deployment" "backend" {
rest_api_id = aws_api_gateway_rest_api.backend.id
stage_name = "default"
triggers = {
redeployment = sha1(join(",", list(
local.api,
data.archive_file.user-management.output_base64sha256
)))
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_api_gateway_method_settings" "backend" {
rest_api_id = aws_api_gateway_rest_api.backend.id
stage_name = aws_api_gateway_deployment.backend.stage_name
method_path = "*/*"
settings {
metrics_enabled = true
logging_level = "INFO"
}
}
For reference, api.json
looks like:
{
"openapi": "3.0.0",
"info": {
"version": "",
"title": ""
},
"paths": {
"/auth": {
"post": {
"summary": "User authentication",
"parameters": [],
"responses": {
"400": {
"description": "Invalid `password`"
}
},
"x-amazon-apigateway-integration": {
"uri": "${service-user-management}",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
}
},
It works well but I want to convert it to API Gateway V2, I have tried that:
resource "aws_apigatewayv2_api" "backend" {
name = "backend-api-2"
description = "Backend API"
protocol_type = "HTTP"
disable_execute_api_endpoint = false
version = "v0.1"
body = local.api
}
resource "aws_apigatewayv2_deployment" "backend-default" {
api_id = aws_apigatewayv2_route.backend.api_id
description = "backend deployment"
lifecycle {
create_before_destroy = true
}
}
resource "aws_apigatewayv2_route" "backend" {
api_id = aws_apigatewayv2_api.backend.id
route_key = "$default"
}
It works well except that none of the endpoints have an integration, no lambda are bound. What are the correct OpenAPI attributes?