具有代理 BadRequest 异常无效映射的 Terraform AWS API 网关

Terraform AWS API Gateway with Proxy BadRequest Exception Invalid Mapping

我正在尝试使用 terraform 创建一个 aws 代理。我目前在应用更改时卡住了。 我在资源“aws_api_gateway_integration”中遇到的错误如下:

Error: Error creating API Gateway Integration: BadRequestException: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Parameter name should match the following regular expression: ^[a-zA-Z0-9:._$-]+$]

这是我的代码:

resource "aws_api_gateway_integration" "itemPutMethod-ApiProxyIntegration" {
  rest_api_id = "${aws_api_gateway_rest_api.apiGateway.id}"
  resource_id = "${aws_api_gateway_resource.itemResource.id}"
  http_method = "${aws_api_gateway_method.itemPutMethod.http_method}"

  type                    = "AWS"
  integration_http_method = "PUT"
  credentials             = "${aws_iam_role.s3_proxy_role.arn}"
  uri                     = "arn:aws:apigateway:${var.region}:s3:path/{bucket}/{folder}/{item}"

  request_parameters = {
    "integration.request.header.x-amz-meta-fileinfo" = "method.request.header.x-amz-meta-fileinfo"
    "integration.request.header.Accept"              = "method.request.header.Accept"
    "integration.request.header.Content-Type "       = "method.request.header.Content-Type"

    "integration.request.path.item"   = "method.request.path.item"
    "integration.request.path.folder" = "method.request.path.folder"
    "integration.request.path.bucket" = "method.request.path.bucket"
  }
}

这是我的方法代码:

resource "aws_api_gateway_method" "itemPutMethod" {
  rest_api_id      = "${aws_api_gateway_rest_api.apiGateway.id}"
  resource_id      = "${aws_api_gateway_resource.itemResource.id}"
  http_method      = "PUT"
  authorization    = "NONE"
  api_key_required = true

  request_parameters = {
    "method.request.header.Accept"              = false
    "method.request.header.Content-Type"        = false
    "method.request.header.x-amz-meta-fileinfo" = false

    "method.request.path.bucket" = true
    "method.request.path.folder" = true
    "method.request.path.item"   = true
  }
}

据我所知,我在参数名称中有一个错误的字符,但我不知道在哪里。任何帮助将不胜感激,谢谢!

API 网关资源

resource "aws_api_gateway_resource" "bucketResource" {
  rest_api_id = "${aws_api_gateway_rest_api.apiGateway.id}"
  parent_id   = "${aws_api_gateway_rest_api.apiGateway.root_resource_id}"
  path_part   = "{bucket}"
}

resource "aws_api_gateway_resource" "folderResource" {
  rest_api_id = "${aws_api_gateway_rest_api.apiGateway.id}"
  parent_id   = "${aws_api_gateway_resource.bucketResource.id}"
  path_part   = "{folder}"
}

resource "aws_api_gateway_resource" "itemResource" {
  rest_api_id = "${aws_api_gateway_rest_api.apiGateway.id}"
  parent_id   = "${aws_api_gateway_resource.folderResource.id}"
  path_part   = "{item}"
}

Link转教程代码: https://github.com/robty123/s3-proxy

您在 aws_api_gateway_integration 资源中的 request_parameters 参数在其中一个映射中有一个 space。这似乎是正则表达式匹配失败的原因。

改变这个

"integration.request.header.Content-Type "       = "method.request.header.Content-Type"

"integration.request.header.Content-Type"       = "method.request.header.Content-Type"