简体   繁体   English

Terraform AWS API Gateway with Proxy BadRequest Exception Invalid Mapping

[英]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.我正在尝试使用 terraform 创建一个 aws 代理。我目前在应用更改时卡住了。 The error I get within the resource "aws_api_gateway_integration" is the following:我在资源“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:._$-]+$]

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 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 to tutorial code: https://github.com/robty123/s3-proxy教程代码链接: https://github.com/robty123/s3-proxy

Your request_parameters argument in aws_api_gateway_integration resource have a space in one of the mappings. aws_api_gateway_integration资源中的request_parameters参数在其中一个映射中有一个空格。 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS API 网关集成和 Terraform - AWS API Gateway Integration and Terraform API 网关集成:BadRequestException:指定的映射表达式无效 Terraform SNS 集成 - API Gateway Integration: BadRequestException: Invalid mapping expression specified Terraform SNS integration Terraform 无服务器应用程序与 AWS Lambda 和 API 网关未知令牌? - Terraform Serverless Applications with AWS Lambda and API Gateway unknown token? terraform - 从文件定义 aws api 网关请求参数? - terraform - define aws api gateway request parameters from file? Terraform 周期错误使用 AWS API 网关计数 - Terraform cycle error using count with AWS API Gateway API 网关 HTTP 与 aws-sam 的代理集成(不是 Lambda 代理) - API Gateway HTTP Proxy integration with aws-sam (NOT Lambda Proxy) 使用 AWS 网关 API 代理从 Python AWS Lambda 重定向 - Redirect from a Python AWS Lambda with AWS Gateway API Proxy Localstack - AWS API 网关使用 Terraform 启用二进制支持 - Localstack - AWS API Gateway enabling binary support using Terraform AWS API 网关反向 Http 代理到 SQS 访问被拒绝 - AWS API Gateway Reverse Http Proxy to SQS Access Denied 无法将 AWS API 网关使用计划引用为 Terraform 中的数据源 - Unable to reference an AWS API Gateway Usage Plan as a data source in Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM