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

(aws-stepfunctions): JsonPath doest not accept strings starting with $[ #22471

Closed
marciocadev opened this issue Oct 12, 2022 · 1 comment · Fixed by #22472
Closed

(aws-stepfunctions): JsonPath doest not accept strings starting with $[ #22471

marciocadev opened this issue Oct 12, 2022 · 1 comment · Fixed by #22472
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p1

Comments

@marciocadev
Copy link
Contributor

marciocadev commented Oct 12, 2022

Describe the bug

When going through a parallel task, the result is an array and to work with it, it needs to be referenced through strings starting with $[

Expected Behavior

Make the JsonPath.listAt function able to process strings starting with $[

Current Behavior

When trying to process a task with the JsonPath.listAt function after a parallel task we get the following error

Error: Data JSON path values must either be exactly equal to '$' or start with '$.'
    at validateDataPath (/home/marcio/marcio/stepfunctions-dynamodb-playground/node_modules/aws-cdk-lib/aws-stepfunctions/lib/fields.js:1:4081)
    at Function.listAt (/home/marcio/marcio/stepfunctions-dynamodb-playground/node_modules/aws-cdk-lib/aws-stepfunctions/lib/fields.js:1:434)

Reproduction Steps

This error can be seen when trying to insert a string set into DynamoDB where the initial input went through a parallel task

const table = new ddb.Table(this, 'Table', {
  partitionKey: { name: 'pk', type: ddb.AttributeType.STRING },
  removalPolicy: cdk.RemovalPolicy.DESTROY,
});

const passPK = new sfn.Pass(this, 'passPK', {
  parameters: { 'pk.$': '$.pk' },
});
const passStringSet = new sfn.Pass(this, 'PassStringSet', {
  parameters: { 'stringset.$': '$.stringset' },
});

const parallel = new sfn.Parallel(this, 'Parallel', {
  resultPath: '$',
});
parallel.branch(passPK)
  .branch(passStringSet);

const putItem = new tasks.DynamoPutItem(this, 'PutItem', {
  table: table,
  item: {
    pk: tasks.DynamoAttributeValue.fromString('$[0].pk'),
    stringset: tasks.DynamoAttributeValue.fromStringSet(sfn.JsonPath.listAt('$[1].stringset')),
  },
});

const definition = sfn.Chain.start(parallel).next(putItem);

new sfn.StateMachine(this, 'StateMachine', {
  definition: definition,
});

Possible Solution

add the possibility for the JsonPath.listAt function to process strings starting with $[

Additional Information/Context

No response

CDK CLI Version

2.45.0

Framework Version

No response

Node.js Version

v18.10.0

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

@marciocadev marciocadev added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 12, 2022
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Oct 12, 2022
@TheRealAmazonKendra TheRealAmazonKendra added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 13, 2022
@mergify mergify bot closed this as completed in #22472 Oct 18, 2022
mergify bot pushed a commit that referenced this issue Oct 18, 2022
…with `$[` (#22472)

`JsonPath.listAt` doest not accept strings starting with `$[`.

When going through a parallel task, the result is an array and to work with it, it needs to be referenced through strings starting with `$[`

This problem particularly affects cases where we want to work with String Sets in DynamoDB where the `DynamoAttributeValue.fromStringSet` function expects an array via the `JsonPath.listAt` function

Closes #22471 

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*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.

mrgrain pushed a commit to mrgrain/aws-cdk that referenced this issue Oct 24, 2022
…with `$[` (aws#22472)

`JsonPath.listAt` doest not accept strings starting with `$[`.

When going through a parallel task, the result is an array and to work with it, it needs to be referenced through strings starting with `$[`

This problem particularly affects cases where we want to work with String Sets in DynamoDB where the `DynamoAttributeValue.fromStringSet` function expects an array via the `JsonPath.listAt` function

Closes aws#22471 

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.

3 participants