gpt4 book ai didi

amazon-web-services - AWS API 网关集成和 Terraform

转载 作者:行者123 更新时间:2023-12-04 17:27:36 30 4
gpt4 key购买 nike

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

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

Execution failed due to configuration error: Unable to transform request

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

用于集成的 Terraform block ;

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

最佳答案

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

因此您需要将此行添加到 aws_api_gateway_integration:

content_handling = "CONVERT_TO_TEXT" 

通常它会解决您的问题。

关于amazon-web-services - AWS API 网关集成和 Terraform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62306547/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com