AWS Step Functions:无法应用 ReferencePath

0 投票
1 回答
23 浏览
提问于 2025-04-13 12:33

我正在尝试做一个步骤函数,但对 "$.<variable>" 这种写法不太确定。为了简化说明,像Lambda函数和S3存储桶这样的资源在infraConstruct中已经定义好了(具体细节可以根据需要提供)。

我的目标是构建两个Lambda函数。第一个函数的任务是读取S3存储桶的内容,并进行一些筛选,确定一些独立的任务来执行。输出结果应该存储在taskArray中。

第二个Lambda函数的目的是对每个任务进行处理。因为这些任务是独立的,所以我选择了mapIterator来并行执行这些任务。

export class StepFunctionStack extends DeploymentStack {
  readonly infra;
  readonly stateMachine;
  readonly stepOneState;
  readonly stepTwoState;
  readonly sfnDefinition;
  readonly mapIterator;

  constructor(scope: Construct, id: string, props: StepFunctionStackProps) {
    super(scope, id, props);
    this.infra = new InfraConstruct(this, id, props);

    this.stepOneState = new LambdaInvoke(this, 'stepOneState', {
      lambdaFunction: this.infra.stepOneLambda,
      resultPath: '$.taskArray',
    });

    this.stepTwoState = new LambdaInvoke(this, 'stepTwoState', {
      lambdaFunction: this.infra.stepTwoLambda,
      resultPath: '$.output',
    });

    this.mapIterator = new Map(this, 'Map State', {
      itemsPath: '$.taskArray.Payload',
      maxConcurrency: 100,
    });

    this.mapIterator.iterator(this.stepTwoState);

    this.sfnDefinition = this.stepOneState.next(this.mapIterator);

    this.stateMachine = new StateMachine(this, 'StateMachine', {
      definition: this.sfnDefinition,
      stateMachineName: 'StateMachine',
      timeout: Duration.minutes(60),
    });
  }
}

第一个Lambda函数运行得很成功!但是,在下一步我遇到的错误是 Unable to apply ReferencePath $.output to input "task_abc",其中 "task_abc" 是第一个Lambda函数返回的元素之一。

需要注意的是,第二个Lambda函数的返回类型是None。也许 $.output 应该被删除。我猜当返回None时,默认行为是返回输入值。

不过,为什么 "$.output" 不能被赋值为一个字符串呢?

1 个回答

0

stepTwoLambda 的结果路径设置为 null,这样就会忽略返回值,把任务的输入值传给下一个任务。

文档:如果你把 ResultPath 设置为 null,系统会把原始输入直接传给输出。使用 "ResultPath": null,这个状态的输入内容会直接复制到输出,不会考虑结果是什么。

撰写回答