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 -> TaskInput cannot select the entire Input #6388

Closed
mrgrain opened this issue Feb 20, 2020 · 4 comments · Fixed by #6483
Closed

StepFunctions -> TaskInput cannot select the entire Input #6388

mrgrain opened this issue Feb 20, 2020 · 4 comments · Fixed by #6483
Assignees
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p1

Comments

@mrgrain
Copy link
Contributor

mrgrain commented Feb 20, 2020

Using TaskInput in step functions, it is impossible to select the entire step input.

I would expect to be able to select the entire input using $, however the JSON path validator expects a path to start with $.

Reproduction Steps

In a newly created project, put this as stack:

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

    const topic = new Topic(this, "topic");

    const definition = new Task(this, "task", {
      task: new PublishToTopic(topic, {
        message: TaskInput.fromDataAt("$")
      })
    });

    new StateMachine(this, "state-machine", {
      stateMachineType: StateMachineType.STANDARD,
      definition
    });
  }
}

Error Log


Data JSON path values must start with '$.'
Subprocess exited with error 1

Environment

  • CLI Version : 1.25.0 (build 5ced526)
  • Framework Version: 1.25.0
  • OS : macOS Mojave 10.14.5
  • Language : Typescript 3.7.5

This is 🐛 Bug Report

@mrgrain mrgrain added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 20, 2020
@SomayaB SomayaB added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Feb 21, 2020
@nija-at
Copy link
Contributor

nija-at commented Feb 26, 2020

This seems to be a fundamental limitation of StepFunctions itself, and not necessarily the CDK.

Based on their documentation, they're using JsonPath. I can't seem to find a way in JsonPath to specify a 'select all' operator. The closest that comes is the $..* operator.

Can you try the $..* and see if this satisfies your use case?

@nija-at nija-at added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Feb 27, 2020

Also, in case of the PublishToTopic action, I believe not specifying a TaskInput at all will make it default to the entire message.

@mrgrain
Copy link
Contributor Author

mrgrain commented Feb 27, 2020

@nija-at StepFunctions is perfecty happy with a $ to include the entire input. It's also how I would read the JsonPath documentation.

@rix0rrr That's good to know, thanks 👍 I still believe the JsonPath parser isnt't correct though, as $ is a valid JsonPath and meets the extra requirements for StepFunctions. See http://jsonpath.herokuapp.com/?path=$


There is another work around as well, but it's not obvious to find:

new PublishToTopic(snsTopic, {
  message: TaskInput.fromText(Data.entirePayload)
})

@nija-at
Copy link
Contributor

nija-at commented Feb 27, 2020

@rix0rrr - Message attribute is a mandatory property for the Notification type in the Amazon states language, so what you're suggesting won't work here.

However, I seem to have missed in the documentation that $ is a valid path that refers to selecting everything. (thanks @rix0rrr for pointing this out).

The validations in field.ts will need to updated to support $ and $$.

function validateDataPath(path: string) {
if (!path.startsWith('$.')) {
throw new Error("Data JSON path values must start with '$.'");
}
}
function validateContextPath(path: string) {
if (!path.startsWith('$$.')) {
throw new Error("Context JSON path values must start with '$$.'");
}

@nija-at nija-at added p1 and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Feb 27, 2020
nija-at pushed a commit that referenced this issue Feb 27, 2020
'$' is a valid reference path that indicates that the entire object
should be selected.

'$$' is a valid selection of the context object that indicates that the
entire context object should be selected.

fixes #6388
@mergify mergify bot closed this as completed in #6483 Feb 27, 2020
mergify bot added a commit that referenced this issue Feb 27, 2020
'$' is a valid reference path that indicates that the entire object
should be selected.

'$$' is a valid selection of the context object that indicates that the
entire context object should be selected.

fixes #6388

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants