我很难将API网关集成请求转换成Terraform代码,我试图将多部分/表单数据请求传递给Lambda存储。
我已经能够从头开始手动设置API网关,但是当我尝试terraform时,我收到了一个内部服务器错误,Cloudwatch告诉我网关无法转换请求。
由于配置错误,
执行失败:无法转换请求
问题似乎在Integration中,因为如果我执行terraform部署,我可以通过将UI中的Integration更改为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'))"
}发布于 2021-04-29 12:32:43
在AWS控制台上,您无法设置Integration的content_handling,而且它也是terraform中的一个可选参数。当您将UI中的Integration更改为Lambda时,集成请求的content_handling将被设置为CONVERT_TO_TEXT。
因此,您需要将该行添加到aws_api_gateway_integration中:
content_handling = "CONVERT_TO_TEXT" 通常情况下它会解决你的问题。
https://stackoverflow.com/questions/62306547
复制相似问题