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

AWS Step Functions/CDK问题:无法为Catch捕获器配置输出

解决CDK中Step Functions Catch捕获器outputs不生效的问题

你在使用aws-cdk-lib 2.178.1版本时,通过jsonata方式定义Step Functions的Glue任务步骤,并为其添加Catch捕获器后,发现设置的outputs参数完全没有生效——部署后的CloudFormation模板里不存在该配置,尝试字符串等多种数据类型均无效。这是当前CDK JSONata API的已知bug,可通过手动覆盖CloudFormation属性的方式解决。

解决方案

使用add_property_override方法直接为Catch规则添加输出配置,对应Step Functions CloudFormation定义中Catch数组的Result(固定输出)、ResultPath或OutputPath字段:

修改后的完整代码示例

from aws_cdk import aws_stepfunctions_tasks as tasks
from aws_cdk import aws_stepfunctions as sfn

states = tasks.GlueStartJobRun.jsonata(
    self,
    "Start_job",
    glue_job_name="{% $states.input %}",
).add_catch(
    sfn.Fail.jsonata(self, "boom"),
    errors=["States.ALL"],
)

# 手动添加Catch的固定字符串输出,注意字符串需用双引号包裹(符合JSON格式)
states.add_property_override("Catch.0.Result", '"a string"')

sfn.StateMachine(
    self,
    "State_machine",
    query_language=sfn.QueryLanguage.JSON_PATH,
    definition_body=sfn.ChainDefinitionBody.from_chainable(states),
)

参数说明

  • 如果需要将错误结果存储到输入的指定路径,替换为ResultPath:
    states.add_property_override("Catch.0.ResultPath", "$.errorDetails")
    
  • 如果需要从捕获结果中提取特定数据作为下一步输入,使用OutputPath:
    states.add_property_override("Catch.0.OutputPath", "$.errorMessage")
    
  • 若存在多个Catch规则,调整索引数字(如Catch.1)对应不同的捕获器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 11:01:02