Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stepfunctions-tasks: StepFunctionsStartExecution should add AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID #14778

Closed
2 tasks
iOnline247 opened this issue May 19, 2021 · 7 comments · Fixed by #16475
Closed
2 tasks
Labels
@aws-cdk/aws-stepfunctions-tasks effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@iOnline247
Copy link
Contributor

iOnline247 commented May 19, 2021

It'd be nice to have a property that'll add the AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID to the input payload.

Use Case

This will make it easy to add the AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID to the input payload.

Proposed Solution

    const finalTransformExecution = new StepFunctionsStartExecution(
        scope,
        'Final Transform',
        {
            stateMachine: finalTransformSfn,
            integrationPattern: IntegrationPattern.RUN_JOB,
            // Proposed property, but horrible name. ;)
            addStartedById: true,
            outputPath: '$.Output',
        },
    );

Other

This would assist in removing some of the workarounds I've implemented to get this to work. #14777

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@iOnline247 iOnline247 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 19, 2021
@shivlaks
Copy link
Contributor

@iOnline247 thanks for adding this feature request. I agree it would be useful to have native support for it.

@shivlaks shivlaks added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 19, 2021
@hassanazharkhan
Copy link
Contributor

@shivlaks Can I pick this up?

@BenChaimberg
Copy link
Contributor

@hassanazharkhan yes, please feel free to open a PR for this feature. I think an appropriate name for the property would be associateWithParent and it should default to true

@kaizencc
Copy link
Contributor

I could be way off base here as I'm trying to understand stepfunctions as a whole still, but it seems odd to have both an input property and the proposed associateWithParent property on StepFunctionsStartExecutionProps. It also seems nontrivial to implement, since associateWithParent would then be tasked with modifying the input property (which may or may not exist).

Instead, would it make more sense to add a new static method in JsonPath like what we do for taskToken()?

public static get taskToken(): string {
return new JsonPathToken('$$.Task.Token').toString();
}

Something like:

public static get executionId(): string {
  return new JsonPathToken('$$.Execution.Id').toString();
}

Then the interface would look like this:

const task = new StepFunctionsStartExecution(this, 'Task', {
  stateMachine,
  input: sfn.TaskInput.fromObject({
    AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID: sfn.JsonPath.executionId,
    token: sfn.JsonPath.taskToken, // this is how taskToken is used in the tests
  }),
}

Tasktoken seems to be one of the other keys modeled in the input property so I figure it makes sense to follow the implementation for that. Am I missing anything here? Happy to take on this issue since I've already invested time in researching this. @BenChaimberg can you take a look?

@BenChaimberg
Copy link
Contributor

BenChaimberg commented Sep 10, 2021

I agree this is nontrivial, but I still think possible. We have information about whether TaskInput is from a constructed object or directly taken from a JSON path. This means we can decide whether or not to support associateWithParent based on what is passed in for input. Something like:

class StepFunctionsStartExecution {
  constructor(...) {
    // ...
    if (this.props.associateWithParent && this.props.input?.type !== sfn.InputType.OBJECT) {
      throw new Error('Could not associate child execution with parent execution because input is taken directly from a JSON path (or a value for the `input` property was not provided). Use `sfn.TaskInput.fromObject` instead');
    }
  }

  _renderTask(): any {
    let input: any;
    if (this.props.associateWithParent) {
      const associateWithParentEntry = {
        AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID: sfn.JsonPath.stringAt('$$.Execution.Id'),
      };
      input = { ...this.props.input.value, ...associateWithParentEntry };
    } else {
      input = this.props.input ? this.props.input.value : sfn.TaskInput.fromJsonPathAt('$').value;
    }
    return {
      // ...
      Parameters: {
        Input: input,
        // ...,
     };
  }
}

I think a executionId static property of JsonPath is a great idea too! Just not a good replacement for this feature IMO

@kaizencc
Copy link
Contributor

I can do that too! I was wary about associateWithParent along with a non Object input but throwing an error there makes so much sense.

@mergify mergify bot closed this as completed in #16475 Sep 15, 2021
mergify bot pushed a commit that referenced this issue Sep 15, 2021
…tepFunctionsStartExecution via associateWithParent property (#16475)

Adds an `associateWithParent` boolean property on `StepFunctionsStartExecutionProps` that is native support for [Associate Workflow Executions](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-nested-workflows.html#nested-execution-startid). It adds the `"AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$": "$$.Execution.Id"` payload to `input`.

This allows the Step Functions UI to link child executions from parent executions, making it easier to trace execution flow across state machines. 

Closes #14778.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions-tasks effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
5 participants