从AWS_API_Gateway_REST_API迁移到AWS_apigatewayv2_API松散的OpenAPI集成 [英] Migrating from aws_api_gateway_rest_api to aws_apigatewayv2_api loose OpenAPI integration
本文介绍了从AWS_API_Gateway_REST_API迁移到AWS_apigatewayv2_API松散的OpenAPI集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个通过Terraform部署的AWS API网关(REST API):
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"
}
}
作为参考,api.json
如下:
{
"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"
}
}
},
它运行良好,但我想将其转换为API Gateway V2,我已经尝试过了:
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"
}
它工作得很好,只是没有一个端点具有集成,没有绑定lambda。 哪些是正确的OpenAPI属性?
推荐答案
实际上opapi格式可能略有变化,而不是直接声明集成,指它起作用了:
{
"openapi": "3.0.0",
"info": {
"version": "",
"title": ""
},
"paths": {
"/auth": {
"post": {
"summary": "User authentication",
"parameters": [],
"responses": {
"400": {
"description": "Invalid `password`"
}
},
"x-amazon-apigateway-integration": {
"$ref": "#/components/x-amazon-apigateway-integrations/user-management"
}
}
...
},
"x-amazon-apigateway-integrations": {
"user-management": {
"uri": "${service-user-management}",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
}
}
这篇关于从AWS_API_Gateway_REST_API迁移到AWS_apigatewayv2_API松散的OpenAPI集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文