【发布时间】:2019-05-31 12:16:20
【问题描述】:
我想使用 terraform 部署我的 api 网关,使用 swagger 文件来描述我的 api。 swagger.yaml 看起来像这样:
swagger: '2.0'
info:
version: '1.0'
title: "CodingTips"
schemes:
- https
paths:
"/api":
get:
description: "Get coding tips"
produces:
- application/json
x-amazon-apigateway-integration: ${apiIntegration}
responses:
'200':
description: "Codingtips were successfully requested"
Terraform 给我一个 BadRequestException 说 The REST API doesn't contain any methods。
因此,我认为它正在尝试部署 REST api,而无需等待创建此 api 的方法和集成。
这让我想到了必须将DEPENDS_ON 添加到aws_api_gateway_deployment 的方向。但是我不知道要依赖什么,因为我没有使用 swagger 定义方法和集成资源。它们应该自动从 swagger 定义中扣除。
我的想法是否正确?如果是,我必须让我的aws_api_gateway_deployment 依赖什么?还是我尝试部署此 api 的方式有其他问题。
我的apigateway.tf 文件如下所示:
resource "aws_api_gateway_rest_api" "codingtips-api-gateway" {
name = "ServerlessExample"
description = "Terraform Serverless Application Example"
body = "${data.template_file.codingtips_api_swagger.rendered}"
}
locals{
"get_codingtips_arn" = "${aws_lambda_function.get-tips-lambda.invoke_arn}"
"x-amazon-coding-tips-apigateway-integration" = <<EOF
#
uri = "${local.get_codingtips_arn}"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
credentials: "${aws_iam_role.api_gateway_role.arn}"
EOF
}
data "template_file" codingtips_api_swagger{
template = "${file("./swagger.yaml")}"
vars {
apiIntegration = "${indent(8, local.x-amazon-coding-tips-apigateway-integration)}"
}
}
resource "aws_api_gateway_deployment" "codingtips-api-gateway-deployment" {
rest_api_id = "${aws_api_gateway_rest_api.codingtips-api-gateway.id}"
stage_name = "test"
}
如何修复BadRequestException: The REST API doesn't contain any methods?
【问题讨论】:
标签: swagger aws-api-gateway terraform