簡體   English   中英

Terraform AWS API Gateway with Proxy BadRequest Exception Invalid Mapping

[英]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}"
}

教程代碼鏈接: https://github.com/robty123/s3-proxy

aws_api_gateway_integration資源中的request_parameters參數在其中一個映射中有一個空格。 這似乎是正則表達式匹配失敗的原因。

改變這個

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM