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: resultwriter on jsonata distributed maps fails deployments #33396

Closed
1 task
nywhere opened this issue Feb 11, 2025 · 5 comments
Closed
1 task
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. p1

Comments

@nywhere
Copy link

nywhere commented Feb 11, 2025

Describe the bug

The following is working with DistributedMaps and JsonPath language:

map = sfn.DistributedMap(
    result_writer=sfn.ResultWriter(
        bucket=s3_bucket, 
        prefix=prefix
    )
)

With JSONata synth is ok, but the deployment fails with:

Resource handler returned message: "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: These fields are required: [Arguments] at /States/Stages/ItemProcessor/States/Stage/ResultWriter'

Meanwhile step function UI designer does add "Arguments":

"ResultWriter": {
    "Resource": "arn:aws:states:::s3:putObject",
    "Arguments": {
        "Bucket": "mybucket",
        "Prefix": "tmp/logs"
    }
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

ResultWriter should still work with JSONata language

Current Behavior

ResultWriter only works with JsonPath language.

Reproduction Steps

  • Create state machine
  • Add a distributed map with JSONata language
  • Add a ResultWriter
  • Deploy

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.178.1 (build ae342cb)

Framework Version

No response

Node.js Version

v18.16.0

OS

OSX 15.3

Language

Python

Language Version

No response

Other information

No response

@nywhere nywhere added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 11, 2025
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Feb 11, 2025
@nywhere nywhere changed the title step functions: resultwriter on jsonata distributed maps step functions: resultwriter on jsonata distributed maps fails deployments Feb 11, 2025
@pahud
Copy link
Contributor

pahud commented Feb 11, 2025

After analyzing the code and issue, here's what I found:

  1. The issue appears to be in the CDK's implementation of the ResultWriter for DistributedMap states when using JSONata language. The ResultWriter class in aws-stepfunctions/lib/states/distributed-map/result-writer.ts doesn't properly handle the required "Arguments" field in the ASL (Amazon States Language) JSON when using JSONata.
  2. According to the AWS Step Functions documentation and the error message, when using ResultWriter with JSONata, the ASL should include an "Arguments" field like this:
"ResultWriter": {
    "Resource": "arn:aws:states:::s3:putObject",
    "Arguments": {
        "Bucket": "mybucket",
        "Prefix": "tmp/logs"
    }
}
  1. The current CDK implementation appears to be missing this required field structure when using JSONata, while it works correctly with JsonPath.

We need to ensure that when JSONata is enabled, the ResultWriter generates the correct field name.

From the documentation, when using JSONata: [1]

The Arguments and Output fields only support JSONata [2]

The InputPath, Parameters, ResultSelector, ResultPath, OutputPath fields only support JSONPath

Specifically, it states:

The Arguments and Output fields only support JSONata, so it is invalid to use them with workflows that use JSONPath. Conversely, InputPath, Parameters, ResultSelector, ResultPath, OutputPath, and other JSONPath fields are only supported in JSONPath, so it is invalid to use path-based fields when using JSONata as your top level workflow or state query language.

This means that when you opt-in to using JSONata in your Step Functions workflow: [3]

  • You must use Arguments instead of Parameters.
  • You cannot mix JSONPath fields with JSONata fields in the same workflow
  • The syntax for JSONata expressions uses {% %} delimiters

Confirmed this is a bug CDK should fix while workarounds are available.

Short-term workaround: Use JsonPath instead of JSONata for now when using ResultWriter with DistributedMap.
Alternative workaround: Define the state machine using raw ASL JSON if you must use JSONata with ResultWriter.

@pahud pahud added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 11, 2025
@pahud
Copy link
Contributor

pahud commented Feb 11, 2025

I'm escalating the team for inputs.

@GavinZZ GavinZZ changed the title step functions: resultwriter on jsonata distributed maps fails deployments stepfunctions: resultwriter on jsonata distributed maps fails deployments Feb 11, 2025
@GavinZZ GavinZZ self-assigned this Feb 11, 2025
@GavinZZ
Copy link
Contributor

GavinZZ commented Feb 12, 2025

Thanks Pahud for the detailed information and thanks @nywhere for reporting this issue. After deep dive, I think this is a valid issue and we should raise the priority to p1 given that if users use JSONata as query language as the top-level language, there is no workaround for users to use JSONPath for Result Writers or Item Readers.

@GavinZZ GavinZZ added p1 and removed p2 labels Feb 12, 2025
GavinZZ added a commit that referenced this issue Feb 13, 2025
…#33423)

### Issue # (if applicable)

Closes #33403 and #33374 and #33396.

### Reason for this change

There are three issues here:
1. For summary, the first issue is basically that assign property cannot
be accessed with using Map.jsonata(...) but available if we directly
create map through new Map(...) using JSONATA query language.
2. For summary, the second issue is that JSONATA main PR added the
outputs and assign property in the CatchProps interface for AddCatch
functionality. But I don't think it's being used in the actual
`addCatch` call
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts#L398.
3. Result writer and item reader class do not support using JSONATA.
Deployment will fails due to if SFN is set to use JSONATA, it expects
`Arguments` in the ASL instead of `Parameters`.

### Description of changes

Fix both issues by fixing the interface inheritance and added the props
to `AddCatch` method.
Support `JSONATA` as the query language.

### Description of how you validated changes

Added integ test and unit test to make sure that 

### Checklist
- [ ] My code adheres to the [CONTRIBUTING
GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and
[DESIGN
GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*
GavinZZ added a commit that referenced this issue Feb 19, 2025
### Issue # (if applicable)

Closes #33403 and #33374 and #33396.

### Reason for this change

There are three issues here:
1. For summary, the first issue is basically that assign property cannot
be accessed with using Map.jsonata(...) but available if we directly
create map through new Map(...) using JSONATA query language.
2. For summary, the second issue is that JSONATA main PR added the
outputs and assign property in the CatchProps interface for AddCatch
functionality. But I don't think it's being used in the actual
`addCatch` call
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts#L398.
3. Result writer and item reader class do not support using JSONATA.
Deployment will fails due to if SFN is set to use JSONATA, it expects
`Arguments` in the ASL instead of `Parameters`.

### Description of changes

Fix both issues by fixing the interface inheritance and added the props
to `AddCatch` method.
Support `JSONATA` as the query language.

### Description of how you validated changes

Added integ test and unit test to make sure that 

### Checklist
- [ ] My code adheres to the [CONTRIBUTING
GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and
[DESIGN
GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@GavinZZ
Copy link
Contributor

GavinZZ commented Feb 19, 2025

Closing this issue as a PR to fix this is merged. Pending next release.

@GavinZZ GavinZZ closed this as completed Feb 19, 2025
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. p1
Projects
None yet
Development

No branches or pull requests

3 participants