【问题标题】:AWS API Gateway Integration and TerraformAWS API 网关集成和 Terraform
【发布时间】:2020-09-30 01:03:18
【问题描述】:

我正在努力将我的 API Gateway 集成请求转换为 Terraform 代码,我正在尝试将 multipart/form-data 请求传递给 Lambda 进行存储。

我已经能够从头开始手动设置 API 网关,但是当我尝试使用 terraform 时,我收到一个内部服务器错误,Cloudwatch 告诉我网关无法转换请求。

由于配置错误,执行失败:无法转换请求

问题似乎出在集成请求中,因为如果我进行 terraform 部署,我可以通过将 UI 中的集成类型更改为 Lambda 代理,再次将其改回并添加重新添加映射模板。

用于集成的 Terraform 块;

resource "aws_api_gateway_integration" "docuemnt-api-method-integration" {
  rest_api_id = aws_api_gateway_rest_api.document-api.id
  resource_id = aws_api_gateway_resource.document-resource.id
  http_method = aws_api_gateway_method.document-post-method.http_method
  type = "AWS"
  uri = aws_lambda_function.document_function.invoke_arn
  integration_http_method = "POST"
  passthrough_behavior = "WHEN_NO_TEMPLATES"
  request_templates = {
    "multipart/form-data" = file("${path.module}/mapping/mapping_template.json")
  }
}

映射模板

{
  "body":"$input.body",
  "content-type": "$util.escapeJavaScript($input.params().header.get('Content-Type'))"
}

【问题讨论】:

    标签: amazon-web-services multipartform-data terraform-provider-aws


    【解决方案1】:

    在 AWS 控制台上,您无法设置集成请求的 content_handling,它也只是 terraform 中的一个可选参数。当您将 UI 中的集成类型更改为 Lambda 代理时,集成请求的 content_handling 将设置为 CONVERT_TO_TEXT。

    所以您需要将此行添加到 aws_api_gateway_integration:

    content_handling = "CONVERT_TO_TEXT" 
    

    通常它会解决你的问题。

    【讨论】:

      猜你喜欢
      • 2019-12-05
      • 2023-03-08
      • 1970-01-01
      • 2020-04-30
      • 2020-06-16
      • 2018-08-15
      • 2017-08-03
      • 2019-12-01
      • 2017-04-27
      相关资源
      最近更新 更多