AWS step 函数:如何在 Fargate 任务中将 InputPath 原样传递给 OutputPath

AWS step function: how to pass InputPath to OutputPath unchanged in Fargate task

我使用这个 Serverless plugin 定义了一个 AWS steps 函数,分 3 个步骤(FirstStep -> Worker -> EndStep -> Done):

stepFunctions:
  stateMachines:
    MyStateMachine:
      name: "MyStateMachine"
      definition:
        StartAt: FirstStep
        States:
          FirstStep:
            Type: Task
            Resource:
              Fn::GetAtt: [ FirstStep, Arn ]
            InputPath: $
            OutputPath: $
            Next: Worker

          Worker:
            Type: Task
            Resource: arn:aws:states:::ecs:runTask.sync
            InputPath: $
            OutputPath: $
            Parameters:
              Cluster: "#{EcsCluster}"
              TaskDefinition: "#{EcsTaskDefinition}"
              LaunchType: FARGATE
              Overrides:
                ContainerOverrides:
                  - Name: container-worker
                    Environment:
                      - Name: ENV_VAR_1
                        'Value.$': $.ENV_VAR_1
                      - Name: ENV_VAR_2
                        'Value.$': $.ENV_VAR_2
            Next: EndStep

            EndStep:
              Type: Task
              Resource:
                Fn::GetAtt: [ EndStep, Arn ]
              InputPath: $
              OutputPath: $
              Next: Done

          Done:
            Type: Succeed

我想将 InputPath 从 Worker 步骤(Fargate)不变地传播到 EndStep,但是当我从 AWS 管理控制台检查 EndStep 的步骤输入时,我看到了该数据改为传递与 Fargate 任务关联的内容:

{
  "Attachments": [...],
  "Attributes": [],
  "AvailabilityZone": "...",
  "ClusterArn": "...",
  "Connectivity": "CONNECTED",
  "ConnectivityAt": 1619602512349,
  "Containers": [...],
  "Cpu": "1024",
  "CreatedAt": 1619602508374,
  "DesiredStatus": "STOPPED",
  "ExecutionStoppedAt": 1619602543623,
  "Group": "...",
  "InferenceAccelerators": [],
  "LastStatus": "STOPPED",
  "LaunchType": "FARGATE",
  "Memory": "3072",
  "Overrides": {
    "ContainerOverrides": [
      {
        "Command": [],
        "Environment": [
          {
            "Name": "ENV_VAR_1",
            "Value": "..."
          },
          {
            "Name": "ENV_VAR_2",
            "Value": "..."
          }
        ],
        "EnvironmentFiles": [],
        "Name": "container-worker",
        "ResourceRequirements": []
      }
    ],
    "InferenceAcceleratorOverrides": []
  },
  "PlatformVersion": "1.4.0",
  "PullStartedAt": 1619602522806,
  "PullStoppedAt": 1619602527294,
  "StartedAt": 1619602527802,
  "StartedBy": "AWS Step Functions",
  "StopCode": "EssentialContainerExited",
  "StoppedAt": 1619602567040,
  "StoppedReason": "Essential container in task exited",
  "StoppingAt": 1619602553655,
  "Tags": [],
  "TaskArn": "...",
  "TaskDefinitionArn": "...",
  "Version": 5
}

基本上,如果初始输入是

{
  "ENV_VAR_1": "env1",
  "ENV_VAR_2": "env2",
  "otherStuff": {
    "k1": "v1",
    "k2": "v2"
  }
}

我希望它原封不动地传递给 FirstStepWorkerEndStep 输入。 这可能吗?

鉴于您使用对象调用步骤函数(我们称之为 A),那么任务的...

  • ...InputPath 指定 A 的哪一部分交给您的任务
  • ...ResultPath 指定 A 中放置任务结果的位置
  • ...OutputPath指定A的哪一部分交给下一个状态

来源:https://docs.aws.amazon.com/step-functions/latest/dg/input-output-example.html

因此,您当前正在使用 Worker 状态的结果(隐含地)覆盖 A 中的所有内容。如果你想丢弃你的 Worker 状态的结果,你必须指定:

ResultPath: null

来源:https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html#input-output-resultpath-null