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

使用EventBridge Pipes集成SQS与Step Function失败求助

问题分析

错误提示$.Messages[0].Body在输入{}中找不到,核心原因是:

  • EventBridge Pipes作为触发源,已经将SQS FIFO队列中的目标消息取出,并把消息内容传递给Step Function作为执行输入
  • Step Function里的Receive Message任务再次调用SQS的receiveMessage时,队列里已经没有这条消息了,返回空结果,导致ResultSelector里的JsonPath解析失败
修复方案

直接移除不必要的Receive Message任务,改用EventBridge Pipes已经传递过来的原始消息内容即可。修改后的Step Function定义如下:

{
  "Comment": "A description of my state machine",
  "StartAt": "Pass",
  "States": {
    "Pass": {
      "Type": "Pass",
      "Next": "List Executions",
      "Parameters": {
        "messageId.$": "$.[0].messageId",
        "receiptHandle.$": "$.[0].receiptHandle",
        "body.$": "$.[0].body",
        "attributes.$": "$.[0].attributes"
      }
    },
    "List Executions": {
      "Type": "Task",
      "Parameters": {
        "StateMachineArn.$": "$$.StateMachine.Id",
        "StatusFilter": "RUNNING"
      },
      "Resource": "arn:aws:states:::aws-sdk:sfn:listExecutions",
      "ResultSelector": {
        "StateMachineArn.$": "$$.StateMachine.Id",
        "uuid.$": "States.UUID()",
        "runningExecutionsCount.$": "States.ArrayLength($.Executions)"
      },
      "Next": "Process Finished",
      "ResultPath": "$.ExecutionDetails"
    },
    "Process Finished": {
      "Type": "Pass",
      "End": true
    }
  }
}
额外优化建议

如果需要解析消息体的JSON格式,直接在Pass状态中对已传入的body字段处理即可,比如在Pass的Parameters里添加:

"parsedBody.$": "States.StringToJson($.[0].body)"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 15:43:37