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

如何通过API Gateway查询参数匹配Step Functions Choice中的设备类型?

解决Step Function从API Gateway查询参数获取deviceType的问题

步骤1:配置API Gateway映射模板,将查询参数传入Step Function输入

在API Gateway对应方法的Integration Request中,找到Mapping Templates:

  • 添加一个模板(选择application/json,若设备请求有特定Content-Type,也可对应设置)
  • 编写VTL模板,把URL中的查询参数deviceType映射到Step Function的输入结构里,示例模板如下:
{
  "body": $input.json('$'),
  "queryParams": {
    "deviceType": "$input.params('deviceType')"
  }
}

这个模板会保留原请求体到body字段,同时将查询参数deviceType存入queryParams字段,让Step Function可以读取到该值。

步骤2:修改Step Function的Choice状态,指向查询参数路径

把最后一个Choice选项的Variable路径改为$.queryParams.deviceType,修改后的状态代码如下:

"Router": {
        "Type": "Choice",
        "Choices": [
          {
            "Variable": "$.deviceType",
            "StringEquals": "queclink-gl501mg",
            "Next": "Queclink GL501MG Uplink"
          },
          {
            "Variable": "$.deviceType",
            "StringEquals": "queclink-gl502mg",
            "Next": "Queclink GL502MG Uplink"
          },
          {
            "Variable": "$.deviceType",
            "StringEquals": "queclink-gl505",
            "Next": "Queclink GL505 Uplink"
          },
          {
            "Variable": "$.deviceType",
            "StringEquals": "tive",
            "Next": "Tive"
          },
          {
            "Variable": "$.queryParams.deviceType",
            "StringEquals": "kkmKG01",
            "Next": "KkmKG01"
          }
        ],
        "Default": "Error"
      }

额外兼容方案(可选)

如果需要同时支持设备从请求体或查询参数传入deviceType,可以给kkmKG01的选项添加Or条件,同时匹配两个路径:

{
  "Or": [
    {
      "Variable": "$.deviceType",
      "StringEquals": "kkmKG01"
    },
    {
      "Variable": "$.queryParams.deviceType",
      "StringEquals": "kkmKG01"
    }
  ],
  "Next": "KkmKG01"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 19:35:23