Amazon web services 使用Terraform返回状态码200在AWS上构建API网关
我是个笨蛋也不知道怎么提问, 实际上我想用TF创建一个API网关,它应该返回状态码200,我尝试了官方的TF示例来创建一个,但是API网关返回的是500而不是200,我无法找出错误是什么,你可以看看我下面的代码,它没有使用lambda或任何东西,我刚刚尝试了模拟端点,但仍然无法理解 TF代码Amazon web services 使用Terraform返回状态码200在AWS上构建API网关,amazon-web-services,terraform,aws-api-gateway,Amazon Web Services,Terraform,Aws Api Gateway,我是个笨蛋也不知道怎么提问, 实际上我想用TF创建一个API网关,它应该返回状态码200,我尝试了官方的TF示例来创建一个,但是API网关返回的是500而不是200,我无法找出错误是什么,你可以看看我下面的代码,它没有使用lambda或任何东西,我刚刚尝试了模拟端点,但仍然无法理解 TF代码 resource "aws_api_gateway_rest_api" "MyDemoAPI" { name = "MyDemoAPI&q
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
path_part = "mydemoresource"
}
resource "aws_api_gateway_method" "MyDemoMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "MyDemoIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "MOCK"
}
resource "aws_api_gateway_method_response" "response_200" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
status_code = "200"
}
resource "aws_api_gateway_integration_response" "MyDemoIntegrationResponse" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
status_code = aws_api_gateway_method_response.response_200.status_code
# Transforms the backend JSON response to XML
response_templates = {
"application/xml" = <<EOF
#set($inputRoot = $input.path('$'))
<?xml version="1.0" encoding="UTF-8"?>
<message>
$inputRoot.body
</message>
EOF
}
}
资源“aws\u api\u网关\u rest\u api”“MyDemoAPI”{
name=“MyDemoAPI”
description=“这是我的API,用于演示”
}
资源“aws\U api\U网关\U资源”“MyDemoResource”{
rest\u api\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.id
父\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.root\u资源\u id
path\u part=“mydemoresource”
}
资源“aws\U api\U网关\U方法”“MyDemoMethod”{
rest\u api\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.id
resource\u id=aws\u api\u gateway\u resource.MyDemoResource.id
http_method=“GET”
授权=“无”
}
资源“aws\U api\U网关\U集成”“MyDemoIntegration”{
rest\u api\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.id
resource\u id=aws\u api\u gateway\u resource.MyDemoResource.id
http\u method=aws\u api\u gateway\u method.MyDemoMethod.http\u method
type=“MOCK”
}
资源“aws\U api\U网关\U方法\U响应”“响应\U 200”{
rest\u api\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.id
resource\u id=aws\u api\u gateway\u resource.MyDemoResource.id
http\u method=aws\u api\u gateway\u method.MyDemoMethod.http\u method
状态代码=“200”
}
资源“aws\U api\U网关\U集成\U响应”“MyDemoIntegrationResponse”{
rest\u api\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.id
resource\u id=aws\u api\u gateway\u resource.MyDemoResource.id
http\u method=aws\u api\u gateway\u method.MyDemoMethod.http\u method
状态\代码=aws\ api\网关\方法\响应.响应\ 200.状态\代码
#将后端JSON响应转换为XML
响应\u模板={
“application/xml”=您尚未为您的MyDemoIntegration
指定request\u模板:
resource "aws_api_gateway_integration" "MyDemoIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "MOCK"
request_templates = {
"application/json" = <<EOF
{
"statusCode": 200
}
EOF
}
}
资源“aws\U api\U网关\U集成”“MyDemoIntegration”{
rest\u api\u id=aws\u api\u网关\u rest\u api.MyDemoAPI.id
resource\u id=aws\u api\u gateway\u resource.MyDemoResource.id
http\u method=aws\u api\u gateway\u method.MyDemoMethod.http\u method
type=“MOCK”
请求\u模板={
“application/json”=进展如何?仍不清楚该怎么办?