You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改UserConfigResponseModel正确声明aws_api_gateway_method_response资源

问题根因
  • 首次报错是因为你直接使用了未提前在当前API Gateway实例中创建的自定义模型名UserConfigResponseModel,系统无法识别该标识符
  • 二次报错是因为你错误将整个aws_api_gateway_model资源对象直接赋值给了response_models参数,该参数要求接收「内容类型:模型名称」格式的键值映射,而非完整的模型资源结构体
正确配置语法

你需要先创建模型资源,再在方法响应中引用模型的name属性即可,完整示例如下:

# 第一步:创建自定义响应模型
resource "aws_api_gateway_model" "user_config_response" {
  rest_api_id  = aws_api_gateway_rest_api.reconciliation_auth.id
  name         = "UserConfigResponseModel"
  description  = "AWS Transfer Family身份提供方所需的用户配置响应结构"
  content_type = "application/json"

  schema = <<EOF
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "UserUserConfig",
  "type": "object",
  "properties": {
    "Role": {"type": "string"},
    "Policy": {"type": "string"},
    "HomeDirectory": {"type": "string"},
    "PublicKeys": {
      "type": "array",
      "items": {"type": "string"}
    }
  }
}
EOF
}

# 第二步:配置方法响应,引用已创建模型的name属性
resource "aws_api_gateway_method_response" "status_200" {
  rest_api_id = aws_api_gateway_rest_api.reconciliation_auth.id
  resource_id = aws_api_gateway_resource.config_path.id
  http_method = aws_api_gateway_method.config_get.http_method
  status_code = "200"

  response_models = {
    "application/json" = aws_api_gateway_model.user_config_response.name
  }
}
查询当前API Gateway合法模型标识符的方法

你可以通过AWS CLI执行以下命令查询当前API下所有已创建的模型名称:

aws apigateway get-models --rest-api-id <你的API ID> --query 'items[].name'

内容的提问来源于stack exchange,提问作者AlexLordThorsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 10:21:03