Skip to content

Commit dc30faa

Browse files
authored
feat(stepfunctions): add support for Jsonata expressions to Map.ItemSelector (#34625)
### Issue Closes #34538. ### Reason for this change In the current implementation `itemSelector` must be an object type `Mapping[str, Any]`, but Step Functions supports both object mappings and JSONata expressions as strings. See the [Amazon States Language](https://states-language.net/spec.html#map-state) specification: > A JSONata Map State MAY have an "ItemSelector" field, whose value MUST be a JSON text, or a JSONata string that evaluates to a JSON text. ### Description of changes This PR adds a new field `jsonataItemSelector` of type `string` to support this use case. This new field is mutually exclusive with `itemSelector` (and `parameters` as it is already mutually exclusive with `itemSelector` and deprecated). During synthesis, if `jsonataItemSelector` is used, then it will be used to render the `ItemSelector` in the cloudformation template. I considered creating a class like the [ProvideItems](https://github.com/aws/aws-cdk/blob/ed08f3f0b8ecd79a2fa5e804acc73a9ff23eab80/packages/aws-cdk-lib/aws-stepfunctions/lib/states/map-base.ts#L60-L77) class, however this would have been a breaking change for existing users. ### Describe any new or updated permissions being added None. ### Description of how you validated changes Added unit tests and an integration test. ### Checklist - [x] 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*
1 parent cedc1b0 commit dc30faa

File tree

15 files changed

+31493
-4
lines changed

15 files changed

+31493
-4
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.map-jsonata-itemselector.js.snapshot/asset.97484721f29e34bf38d7a459804dd2d2a8dea6f8c27d7531e215bf4274fbc895.bundle/index.js

Lines changed: 30674 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.map-jsonata-itemselector.js.snapshot/cdk-stepfunctions-map-jsonata-itemselector-stack.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"Resources": {
3+
"StateMachineRoleB840431D": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "states.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
}
18+
}
19+
},
20+
"StateMachine2E01A3A5": {
21+
"Type": "AWS::StepFunctions::StateMachine",
22+
"Properties": {
23+
"DefinitionString": "{\"StartAt\":\"My-Map-State\",\"States\":{\"My-Map-State\":{\"Type\":\"Map\",\"QueryLanguage\":\"JSONata\",\"End\":true,\"ItemSelector\":\"{% {\\\"foo\\\": \\\"foo\\\", \\\"bar\\\": $states.input.bar} %}\",\"ItemProcessor\":{\"ProcessorConfig\":{\"Mode\":\"INLINE\"},\"StartAt\":\"Pass State\",\"States\":{\"Pass State\":{\"Type\":\"Pass\",\"End\":true}}},\"MaxConcurrency\":1}},\"TimeoutSeconds\":30}",
24+
"RoleArn": {
25+
"Fn::GetAtt": [
26+
"StateMachineRoleB840431D",
27+
"Arn"
28+
]
29+
}
30+
},
31+
"DependsOn": [
32+
"StateMachineRoleB840431D"
33+
],
34+
"UpdateReplacePolicy": "Delete",
35+
"DeletionPolicy": "Delete"
36+
}
37+
},
38+
"Outputs": {
39+
"ExportsOutputRefStateMachine2E01A3A5BA46F753": {
40+
"Value": {
41+
"Ref": "StateMachine2E01A3A5"
42+
},
43+
"Export": {
44+
"Name": "cdk-stepfunctions-map-jsonata-itemselector-stack:ExportsOutputRefStateMachine2E01A3A5BA46F753"
45+
}
46+
}
47+
},
48+
"Parameters": {
49+
"BootstrapVersion": {
50+
"Type": "AWS::SSM::Parameter::Value<String>",
51+
"Default": "/cdk-bootstrap/hnb659fds/version",
52+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
53+
}
54+
},
55+
"Rules": {
56+
"CheckBootstrapVersion": {
57+
"Assertions": [
58+
{
59+
"Assert": {
60+
"Fn::Not": [
61+
{
62+
"Fn::Contains": [
63+
[
64+
"1",
65+
"2",
66+
"3",
67+
"4",
68+
"5"
69+
],
70+
{
71+
"Ref": "BootstrapVersion"
72+
}
73+
]
74+
}
75+
]
76+
},
77+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
78+
}
79+
]
80+
}
81+
}
82+
}

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.map-jsonata-itemselector.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.map-jsonata-itemselector.js.snapshot/cdkstepfunctionsmapitemselectorintegDefaultTestDeployAssertB0D765C3.assets.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)