简体   繁体   中英

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

I have an AWS steps function defined using this Serverless plugin with 3 steps (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

I would like to propagate the InputPath unchanged from Worker step (Fargate) to EndStep , but when I inspect step input of EndStep from AWS management console I see that data associated with Fargate task is passed instead:

{
  "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
}

Basically, if the initial input is

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

I want it to be passed as is to FirstStep , Worker and EndStep inputs without changes. Is this possible?

Given that you invoke the step function with an object (let's call that A ), then a task's...

  • ... InputPath specifies what part of A is handed to your task
  • ... ResultPath specifies where in A to put the result of the task
  • ... OutputPath specifies what part of A to hand over to the next state

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

So you are currently overwriting all content in A with the result of your Worker state (implicitly). If you want to discard the result of your Worker state, you have to specify:

ResultPath: null

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM