简体   繁体   中英

Terraform AWS API Gateway with Proxy BadRequest Exception Invalid Mapping

I am trying to create an aws proxy with terraform. I am currently stuck when applying the changes. The error I get within the resource "aws_api_gateway_integration" is the following:

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:._$-]+$]

Here is my code:

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"
  }
}

And here is my code for the method:

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
  }
}

As far as I understand I have a bad character in the parameter names but I can't figure out where. Any help would be greatly appreciated, thank you!

API Gateway Resource

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 to tutorial code: https://github.com/robty123/s3-proxy

Your request_parameters argument in aws_api_gateway_integration resource have a space in one of the mappings. That seems to be the cause of failing regex match.

Change this

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM