[英]AWS API Gateway Integration and Terraform
I'm struggling to translate my API Gateway Integration request into Terraform code, I'm trying to pass a multipart/form-data request to a Lambda for storage.我正在努力将我的 API 网关集成请求转换为 Terraform 代码,我正在尝试将多部分/表单数据请求传递给 Lambda 进行存储。
I've been able to set up the API gateway manually from scratch, but when I try the terraform I recieve an Internal server error and Cloudwatch tells me the gateway has been unable to transform the request.我已经能够从头开始手动设置 API 网关,但是当我尝试 terraform 时,我收到内部服务器错误并且 Cloudwatch 告诉我网关无法转换请求。
Execution failed due to configuration error: Unable to transform request
由于配置错误导致执行失败:无法转换请求
The problem seems to be in the Integration request, because if I do the terraform deployment I can get the whole thing to work by changing the Integration Type in the UI to Lambda Proxy, changing it back again and adding re-adding the Mapping Template.问题似乎出在集成请求中,因为如果我执行 terraform 部署,我可以通过将 UI 中的集成类型更改为 Lambda 代理,再次将其更改回来并重新添加映射模板来使整个工作正常进行。
Terraform block for the Integration; 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")
}
}
The Mapping template映射模板
{
"body":"$input.body",
"content-type": "$util.escapeJavaScript($input.params().header.get('Content-Type'))"
}
On the AWS console you are NOT able to set the Integration Request's content_handling and it is only an Optional parameter in terraform as well.在 AWS 控制台上,您无法设置集成请求的 content_handling,它也只是 terraform 中的可选参数。 When you are changing the Integration Type in the UI to Lambda Proxy, the integration request's content_handling will be set to CONVERT_TO_TEXT.
当您将 UI 中的集成类型更改为 Lambda 代理时,集成请求的 content_handling 将设置为 CONVERT_TO_TEXT。
So you need to add this row to the aws_api_gateway_integration:因此,您需要将此行添加到 aws_api_gateway_integration:
content_handling = "CONVERT_TO_TEXT"
And normally it will solve your problem.通常它会解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.