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

fix(stepfunctions): cannot use intrinsic functions in Fail state #30193

Closed
wants to merge 3 commits into from

Conversation

sakurai-ryo
Copy link
Contributor

@sakurai-ryo sakurai-ryo commented May 14, 2024

Issue # (if applicable)

Closes #30063

Reason for this change

In the Fail state, we can specify intrinsic functions and json paths as the CausePath and ErrorPath properties.
Currently, however, specifying intrinsic functions as a string will result in an error.
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html

export class SampleStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const fail = new stepfunctions.Fail(this, "Fail", {
      errorPath: "$.error", // OK
      causePath: "States.Format('cause: {}', $.cause)", // Error
    });

    const sm = new stepfunctions.StateMachine(this, "StateMachine", {
      definitionBody: stepfunctions.DefinitionBody.fromChainable(fail),
      timeout: cdk.Duration.minutes(5)
    });
  }
}
Error: Expected JSON path to start with '$', got: States.Format('cause: {}', $.cause)

Description of changes

The value passed to the renderJsonPath function is expected to be a string starting with $ if it is not a token.
However, if you pass intrinsic functions as strings to the CausePath and ErrorPath properties, they will never start with $.
Therefore, I fixed not to call the renderJsonPath function if the intrinsic functions are specified as strings.

Another change was the addition of validation since error and errorPath, cause and causePath cannot be specified simultaneously.

Description of how you validated changes

I added unit tests to verify that passing intrinsic functions as strings do not cause an error.

Tests were also added to verify that errors occur when errors and paths are specified at the same time and when cause and cause paths are specified at the same time.
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html#:~:text=%2C%20and%20States.UUID.-,Important,-You%20can%20specify%20either%20Cause
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html#:~:text=%2C%20and%20States.UUID.-,Important,-You%20can%20specify%20either%20Error

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team May 14, 2024 17:20
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels May 14, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@sakurai-ryo
Copy link
Contributor Author

Exemption Request
I think that unit tests cover the scope of this change.

@sakurai-ryo sakurai-ryo changed the title fix(stepfunctions): cannot use intrinsic functions in Fail state fix(stepfunctions): cannot use intrinsic functions in Fail May 14, 2024
@sakurai-ryo sakurai-ryo marked this pull request as draft May 14, 2024 19:10
@sakurai-ryo sakurai-ryo marked this pull request as ready for review May 14, 2024 19:11
@sakurai-ryo sakurai-ryo changed the title fix(stepfunctions): cannot use intrinsic functions in Fail fix(stepfunctions): cannot use intrinsic functions in Fail state May 14, 2024
@sakurai-ryo
Copy link
Contributor Author

sakurai-ryo commented May 14, 2024

For some reason, the pr/needs-maintainer-review label is not attached.
#30193 (review) should have to be dismissed.

@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 39f6572
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p1 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

step function: Fail state cause_path generates error using States.Format
2 participants