如何解决 创建 Amazon API Gateway API 时出现的 "Execution failed due to configuration error: Illegal character in path" 错误?

1 分钟阅读
0

我正在使用 AWS CloudFormation 模板(或 OpenAPI API 定义)创建具有代理资源的 Amazon API Gateway API。当我创建 API 时,出现以下错误: "Execution failed due to configuration error: Illegal character in path."

简短描述

如果未定义代理路径参数 ({proxy+}) 的 URL 路径参数映射,则 API Gateway 会返回以下错误: "Execution failed due to configuration error: Illegal character in path.:

Without a URL path parameter mapping defined for this parameter in the integration request, API Gateway evaluates the parameter as the literal string "{proxy+}".由于 “{” 不是有效字符,因此发生这种情况时 API Gateway 会返回错误。

要解决错误,请执行以下操作,为集成请求中的代理路径参数定义 URL 路径参数映射:

解决方法

  1. API Gateway 控制台中,选择 API 的名称。
  2. 在“**资源”**窗格中选择方法后,在“**方法执行”**窗格中选择“集成请求”。
  3. 集成请求窗格中,确认端点 URL 使用了正确的代理路径参数:{proxy}。(没有 “+” 的贪婪路径变量。) 例如:http://example.com/{proxy}
  4. 展开 URL 路径参数。然后,选择添加路径并执行以下操作:
    对于名称,输入代理。这对应于端点 URL 中的参数。
    对于映射自,输入 method.request.path.proxy
    注意:这里的代理对应于“方法请求” 窗格中定义的请求路径的名称。此请求路径是通过创建名为 {proxy} 的代理资源来添加的,对于贪婪的路径变量,则为 {proxy+}
  5. 选择复选标记图标(创建)。
    **注意:如果收到“指定的映射表达式无效”**错误,请更新 AWS CloudFormation 模板或 OpenAPI 定义。然后,重复前面的步骤。
  6. 部署 API。

相关信息

设置具有代理资源的代理集成

使用 API Gateway 控制台设置请求和响应数据映射

使用 API Gateway 控制台设置 API 集成请求

AWS 官方
AWS 官方已更新 7 个月前