AWS API Gateway追加查询字符串两次

时间:2019-11-01 15:43:16

标签: terraform aws-api-gateway

我正在尝试通过AWS API Gateway设置一个简单的演示终端节点。波纹管是描述它的Terraform清单。

它实际上是一个GET /demo/hello/world端点,它接受查询字符串参数return_to

terraform可以在AWS中正确创建所有资源。

但是,当我随后向/demo/hello/world?return_to=bbb处的网关发出请求时,后端服务会收到此请求:

/demo/hello/world%3Freturn_to=bbb?return_to=bbb

如您所见,API网关中的?return_to=bbb被URL编码,就好像它是路径的一部分,然后在末尾附加了另一个查询字符串。

有人可以帮助我解决此问题吗?我已经进行了所有设置几个小时,无法知道问题是什么以及如何解决。

resource "aws_api_gateway_rest_api" "api" {
  name        = "origin-${var.name}.${data.terraform_remote_state.setup.outputs.domain-name}"
  description = "Proxy to handle requests to our API test"

}

resource "aws_api_gateway_resource" "demo" {
  depends_on = ["aws_api_gateway_rest_api.api"]

  rest_api_id = "${aws_api_gateway_rest_api.api.id}"
  parent_id   = "${aws_api_gateway_rest_api.api.root_resource_id}"
  path_part   = "demo"
}

resource "aws_api_gateway_resource" "hello" {
  depends_on = ["aws_api_gateway_rest_api.api", "aws_api_gateway_resource.demo"]

  rest_api_id = "${aws_api_gateway_rest_api.api.id}"
  parent_id   = "${aws_api_gateway_resource.demo.id}"
  path_part   = "hello"
}

resource "aws_api_gateway_resource" "world" {
  depends_on = ["aws_api_gateway_rest_api.api", "aws_api_gateway_resource.hello"]

  rest_api_id = "${aws_api_gateway_rest_api.api.id}"
  parent_id   = "${aws_api_gateway_resource.hello.id}"
  path_part   = "world"
}

resource "aws_api_gateway_method" "hello-world" {
  depends_on = ["aws_api_gateway_resource.world"]

  rest_api_id           = "${aws_api_gateway_rest_api.api.id}"
  resource_id           = "${aws_api_gateway_resource.world.id}"
  http_method           = "GET"
  authorization         = "NONE"

  request_parameters = {
    "method.request.querystring.return_to" = true
  }
}

resource "aws_api_gateway_integration" "hello-world" {
  depends_on = ["aws_api_gateway_method.hello-world"]

  rest_api_id             = "${aws_api_gateway_rest_api.api.id}"
  resource_id             = "${aws_api_gateway_resource.world.id}"
  http_method             = "${aws_api_gateway_method.hello-world.http_method}"
  integration_http_method = "GET"
  type                    = "HTTP"
  uri                     = "http://${lookup(var.demo-map, var.environment)}/demo/hello/world"

  connection_type = "VPC_LINK"
  connection_id   = "${data.aws_api_gateway_vpc_link.vpclink.id}"

  request_parameters = {
    "integration.request.querystring.return_to" = "method.request.querystring.return_to"
  }
}

1 个答案:

答案 0 :(得分:1)

我有同样的错误。将查询参数放在aws_api_gateway_method中并从aws_api_gateway_integration中删除解决了我的问题