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

CDKv2迁移报错:state.Retry is not iterable 问题咨询

CDKv2迁移时遇到TypeError: state.Retry is not iterable的解决方法

错误信息

TypeError: state.Retry is not iterable
    at CustomState.toStateJson (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/custom-state.js:1:1844)
    at StateGraph.toGraphJson (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-graph.js:1:2159)
    at Map.renderIterator (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/state.js:1:7229)
    at Map.toStateJson (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/map.js:1:1474)
    at StateGraph.toGraphJson (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-graph.js:1:2159)
    at ChainDefinitionBody.bind (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-machine.js:1:12008)
    at new StateMachine (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-machine.js:1:6368)
    at InvoiceBatchesLambdaExecutor.createStateMachine (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/dist/lib/workflows/invoice-batches-lambda-executor.js:16:16)
    at new InvoiceBatchesLambdaExecutor (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/dist/lib/workflows/invoice-batches-lambda-executor.js:13:34)
    at new WorkflowStack (/Users/abhiwal/workspace/UpayCore/src/UPayCoreServiceCDK/dist/lib/stacks/workflow-stack.js:22:45)

Node.js v18.19.1

Subprocess exited with error 1
 ›   Error: Failed to run CDK CLI

环境信息

使用的aws-cdk-lib版本为^2.118.0

解决步骤

  • 修正CustomState的Retry配置格式:错误根源是CDK期望CustomState的retry属性是可迭代的数组,但代码中可能直接传入了单个Retry对象。将retry: singleRetryObject修改为retry: [singleRetryObject]即可。
  • 检查Map状态内的子状态配置:错误栈显示问题出在Map状态的迭代器渲染环节,确认Map内部的CustomState是否都正确使用数组格式配置Retry策略。
  • 清理并重新安装依赖:若配置无误,可能是依赖缓存导致的异常,执行以下命令:
    rm -rf node_modules package-lock.json
    npm install
    
  • 升级CDK版本:2.118.0版本可能存在该已知bug,升级到最新稳定版本尝试解决:
    npm install aws-cdk-lib@latest
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 17:17:50