-
Notifications
You must be signed in to change notification settings - Fork 4k
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] Support for ResultSelector #9904
Comments
It's not clear from #9821 whether the scope is going to be widened to include |
I would definitely like to get rid of my CustomState objects and use ResultSelector directly. And it would be cool to have support for adding any custom attributes to all the regular state objects, in case more features are added to Step Functions. |
reopening so we can track this feature in this issue rather than lump it into the issue for Conditions |
So for ResultSelector this is my proposal: We add a resultSelector entry to State - I know that ResultSelector is not relevant for all state types (only Parallel, Task and Map) the current design is to include all the feature and let the sub classes use and provide what they do. A Result Selector's values are simply key value pairs so I'm not sure if we should create a ResultSelector type or just make the type of the resultSelector field some kind of key:value store so definition: resultSelector?: { [name: string]: string }; I do think this would be adequate. Then we add a method to the relevant types: addResultSelector which takes this type { [name:string]: string }. This method gets added only to the "states" that support the ResultSelector - TaskStateBase (for tasks) Parallel and Map. Then we add a method renderResultSelector to State which is then called from the toStateJson method in Map, TaskStateBase and Parallel. We could potentially choose to create a new ResultSelector type - not entirely sure if this is necessary or appropriate - though I do not see many places where they're using a key -> value structure (which is what you'd need here). |
@michaelwiles - I had a similar initial thought (start with adding it into |
Thanks - not being fluent in typescript I didn't feel confident to start this. So glad it's being taken up. |
Expanding on @kennu's solution - this is what I'm using in the meantime: import {LambdaInvoke, LambdaInvokeProps} from "@aws-cdk/aws-stepfunctions-tasks";
import {Construct} from "@aws-cdk/core";
export interface LambdaInvokeWithResultSelectorProps extends LambdaInvokeProps {
readonly resultSelector?: object
}
/**
* Custom lambda invoker so we can use ResultSelector to filter out all the Lambda Task metadata.
* See https://github.com/aws/aws-cdk/issues/9904
*/
export class LambdaInvokeWithResultSelector extends LambdaInvoke {
private readonly resultSelector?: object
constructor(scope: Construct, id: string, props: LambdaInvokeWithResultSelectorProps) {
super(scope, id, props);
this.resultSelector = props.resultSelector
}
public toStateJson(): object {
const stateJson: any = super.toStateJson();
if (this.resultSelector !== undefined) {
stateJson.ResultSelector = this.resultSelector
}
return stateJson
}
} FYI: I'm a TS noob, so please be gentle. :-) |
Would be awesome to have this included in CDK. |
Will be great to see this. Here is my shorter and messier hack. export class LambdaInvokeResultSelector extends LambdaInvoke {
constructor(
construct: Construct,
id: string,
private xProps: LambdaInvokeProps & {
resultSelector?: { [key: string]: any };
}
) {
super(construct, id, xProps);
}
// eslint-disable-next-line @typescript-eslint/ban-types
public toStateJson(): object {
return {
...super.toStateJson(),
ResultSelector: this.xProps.resultSelector || undefined
};
}
} |
@thantos @cameronsstone @kennu Thank you for the work around. Are we still missing an ingredient to cook up the following resultSelector: "$.Payload",
resultPath: "$.Items", AKA... trying to get an array of items that's returned in the payload merged in with the state input under Items. @shivlaks Is this a use case that the one you're working on will handle? Looking forward to having all the ingredients for the Input and Output processing dance. EDIT: without an extra level $.Items.Items or clobbering the state input Yeah; it looks like https://states-language.net/#payload-template must be an object and can't be a json path to an array or string. Would be nice if it could be expanded to not squash the non object value cases. Unless there's some other way of processing the input and output without adding an extra level? |
Note that the requirement to return an object is in the result selector API on Sfn, not a limitation of CDK or Cfn. +1 on greater control of outputs. Merging an object (multiple named fields) with the state, setting primatives and arrays as outputs, omitting state fields without listing current fields. |
@wong-a, thank you! will do. I think think there's a fairly small addition that could be made to fill in these non object cases. For now I added an extra object wrapper and carried on... but continue to lose chucks of time when hitting such use cases. |
Still waiting. |
I'm going to be picking this one up this weekend. shooting for a PR next week. |
@shivlaks Can you please provide an update for this? Thanks! |
Any update on this? |
@aaronbfagan I put up a PR up for this yesterday. Waiting for review from CDK maintainers. |
@Vinith1994 @aaronbfagan - @wong-a beat me to it and i'm reviewing the PR. we'll try to get this merged soon |
### Description Adds support for `ResultSelector`. [ResultSelector](https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-resultselector) was added to ASL in August 2020 and is currently missing coverage in CDK. This change exposes a new `resultSelector` field to Task, Map, and Parallel state props. This is a JSON object that functions similarly to `Parameters` but where `$` refers to the state's raw result instead of the state input. This allows you to reshape the result without using extra Pass states. The implementation mimics what exists for Parameters. I'm not convinced we need extra types here. #### Example ```ts new tasks.LambdaInvoke(this, 'Invoke Handler', { lambdaFunction: fn, resultSelector: { lambdaOutput: sfn.JsonPath.stringAt('$.Payload'), invokeRequestId: sfn.JsonPath.stringAt('$.SdkResponseMetadata.RequestId'), staticValue: 'foo', }, }) ``` Which produces the following ASL: ```json { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { "FunctionName": ${functionName}, "Payload.$": "$" }, "ResultSelector": { "lambdaOutput.$": "$.Payload", "invokeRequestId.$": "$.SdkResponseMetadata.RequestId", "staticValue": "foo", }, "Next": ${nextState} } ``` ### Testing * Unit tests for Map, Task, and Parallel states to include `resultSelector` * Unit test with ResultSelector for `LambdaInvoke` state updated to include `resultSelector` * Updated LambdaInvoke integ test to use ResultSelector for one of the states. Executed state machine manually through the AWS console to ensure the example actually works too. Closes #9904 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
commit 35a6202 Author: Ben Chaimberg <chaimber@amazon.com> Date: Tue May 18 10:18:39 2021 -0700 move supported conditions to function-base and minor name changes commit 7c6c217 Author: Ben Chaimberg <chaimber@amazon.com> Date: Mon May 17 20:23:55 2021 -0700 remove extraneous whitespace commit 02cf427 Author: Ben Chaimberg <chaimber@amazon.com> Date: Mon May 17 17:31:01 2021 -0700 add conditions snippet to README commit 8ebf049 Author: Ben Chaimberg <chaimber@amazon.com> Date: Mon May 17 17:22:25 2021 -0700 format README commit af2be84 Merge: ea53bcc 8856482 Author: Ben Chaimberg <chaimber@amazon.com> Date: Mon May 17 17:19:14 2021 -0700 Merge branch 'master' of github.com:aws/aws-cdk into chaimber/lambda_perm_cond commit ea53bcc Merge: 988b66c 1a695e2 Author: Ben Chaimberg <chaimber@amazon.com> Date: Mon May 17 17:16:10 2021 -0700 Merge branch 'chaimber/lambda_perm_cond' of github.com:aws/aws-cdk into chaimber/lambda_perm_cond commit 988b66c Author: Ben Chaimberg <chaimber@amazon.com> Date: Mon May 17 17:10:48 2021 -0700 add documentation for Permission to README commit 8856482 Author: Elad Ben-Israel <benisrae@amazon.com> Date: Mon May 17 23:19:30 2021 +0300 chore: set license of eslint-plugin-cdk (#14720) Fixes #14594 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit b70a5fa Author: Carter Van Deuren <carterv@users.noreply.github.com> Date: Mon May 17 11:29:47 2021 -0700 docs(kinesis): correct grantRead and grantWrite comments (#14707) This commit swaps the comments for `grantRead` and `grantWrite` so that the comments match the permissions being granted. No extra verification was done for this change, as it only effects comments. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit f65d826 Author: Jared Short <jaredlshort@gmail.com> Date: Mon May 17 13:38:57 2021 -0400 docs(stepfunctions-tasks): fix integration patterns of step-function-task docs (#14722) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 50d486a Author: Adam Wong <55506708+wong-a@users.noreply.github.com> Date: Mon May 17 10:12:49 2021 -0700 feat(stepfunctions): Add support for ResultSelector (#14648) ### Description Adds support for `ResultSelector`. [ResultSelector](https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-resultselector) was added to ASL in August 2020 and is currently missing coverage in CDK. This change exposes a new `resultSelector` field to Task, Map, and Parallel state props. This is a JSON object that functions similarly to `Parameters` but where `$` refers to the state's raw result instead of the state input. This allows you to reshape the result without using extra Pass states. The implementation mimics what exists for Parameters. I'm not convinced we need extra types here. #### Example ```ts new tasks.LambdaInvoke(this, 'Invoke Handler', { lambdaFunction: fn, resultSelector: { lambdaOutput: sfn.JsonPath.stringAt('$.Payload'), invokeRequestId: sfn.JsonPath.stringAt('$.SdkResponseMetadata.RequestId'), staticValue: 'foo', }, }) ``` Which produces the following ASL: ```json { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { "FunctionName": ${functionName}, "Payload.$": "$" }, "ResultSelector": { "lambdaOutput.$": "$.Payload", "invokeRequestId.$": "$.SdkResponseMetadata.RequestId", "staticValue": "foo", }, "Next": ${nextState} } ``` ### Testing * Unit tests for Map, Task, and Parallel states to include `resultSelector` * Unit test with ResultSelector for `LambdaInvoke` state updated to include `resultSelector` * Updated LambdaInvoke integ test to use ResultSelector for one of the states. Executed state machine manually through the AWS console to ensure the example actually works too. Closes #9904 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 4da78f6 Author: Kyle Roach <kroach.work@gmail.com> Date: Mon May 17 12:45:39 2021 -0400 feat(apigatewayv2): http api - lambda authorizer (#13181) Second part of #10534 Had to make small changes to `authorizerType` that route expects, since Route and Authorizer enums are not the same. See #10534 (comment). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 49d18ab Author: Austin Yattoni <austinyattoni@gmail.com> Date: Mon May 17 11:18:49 2021 -0500 fix(lambda): unable to access SingletonFunction vpc connections (#14533) fixes #6261 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 8154e91 Author: Nick Lynch <nlynch@amazon.com> Date: Mon May 17 15:29:02 2021 +0100 chore: skip Go proxy for lambda-go integ tests (#14727) Privacy-conscious users and/or organizations may choose to skip sending all package requests to the Google proxy (as is default). Some corporate environments may block network access to proxy.golang.org altogether. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 3bca822 Author: Nick Lynch <nlynch@amazon.com> Date: Mon May 17 11:47:57 2021 +0100 chore(msk): add ignore-assets pragma to cluster integ test (#14725) The MSK module relies on custom resources, which in turn create a Lambda function with assets. The way the current (lerna/yarn) build works includes the .ts file (as well as the .d.ts and .js) files in the asset bundle. Using the new `nozem` build (correctly) only includes the .d.ts and .js files, leading to a different asset hash. Since we don't care about the actual hash anyway, adding the ignore-assets pragma so this test can pass with either build tool. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit fb0977a Merge: 1effc9f df89694 Author: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Date: Sat May 15 00:59:26 2021 +0000 chore(merge-back): 1.104.0 (#14708) See [CHANGELOG](https://github.com/aws/aws-cdk/blob/merge-back/1.104.0/CHANGELOG.md) commit df89694 Merge: 44d3383 1effc9f Author: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Date: Sat May 15 00:33:23 2021 +0000 Merge branch 'master' into merge-back/1.104.0 commit 1effc9f Author: Hsing-Hui Hsu <hsinghui@amazon.com> Date: Fri May 14 15:18:14 2021 -0700 docs(ecs): add contributing guide (#14672) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 44d3383 Merge: bc13a66 aaa0d05 Author: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Date: Fri May 14 21:59:31 2021 +0000 chore(release): 1.104.0 (#14706) See [CHANGELOG](https://github.com/aws/aws-cdk/blob/bump/1.104.0/CHANGELOG.md) commit aaa0d05 Author: Neta Nir <neta1nir@gmail.com> Date: Fri May 14 14:33:52 2021 -0700 Update CHANGELOG.md commit 0328b03 Author: AWS CDK Team <aws-cdk@amazon.com> Date: Fri May 14 21:30:07 2021 +0000 chore(release): 1.104.0 commit 348e11e Author: Madeline Kusters <80541297+madeline-k@users.noreply.github.com> Date: Fri May 14 14:27:19 2021 -0700 fix(ecs): Classes FargateService and Ec2Service have no defaultChild (#14691) * fix(ecs): Class FargateService has no defaultChild fixes #14665 * update unit tests commit 1a695e2 Merge: 84045fd d82de05 Author: Ben Chaimberg <chaimber@amazon.com> Date: Fri May 14 11:45:50 2021 -0700 Merge branch 'master' into chaimber/lambda_perm_cond commit d82de05 Author: Bryan Pan <bryanpan342@gmail.com> Date: Thu May 13 08:48:46 2021 -0700 chore(appsync): rds data source service integration with grantDataApi (#14671) Utilize the `grantDataApi` from RDS to complete service integration. Fixes: #13189 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 8296623 Author: Hsing-Hui Hsu <hsinghui@amazon.com> Date: Thu May 13 08:22:23 2021 -0700 test(ecs-patterns): update l3 fargate integ tests (#14668) This adds integ tests for NLB fargate services -- previously, there were duplicate ALB fargate services being spun up. Also gives integ test stacks unique names. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit b240f6e Author: Nick Lynch <nlynch@amazon.com> Date: Thu May 13 14:21:05 2021 +0100 feat(cloudwatch): GraphWidget supports period and statistic (#14679) Dashboard metric widgets support overridding/setting both period and stat on the widget as a whole. This is often useful in combination with `MathExpression` metrics. Reference: https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Dashboard-Body-Structure.html#CloudWatch-Dashboard-Properties-Metric-Widget-Object ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 3063818 Author: Madeline Kusters <80541297+madeline-k@users.noreply.github.com> Date: Thu May 13 02:29:45 2021 -0700 fix(events-targets): circular dependency when adding a KMS-encrypted SQS queue (#14638) fixes #11158 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 9d97b7d Author: Mitchell Valine <valinm@amazon.com> Date: Thu May 13 02:01:08 2021 -0700 chore: init templates use node jest environment (#14632) Remove usage of the `jsdom` test environment in init templates to speed up unit testing by default. Testing: ran cdk init --language=(typescript|javascript) against local build of CLI then ran yarn test to verify that the testing config was valid and jest correctly used the node environment. fix: #14630 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 282d242 Author: Adam Ruka <adamruka@amazon.com> Date: Thu May 13 00:37:33 2021 -0700 chore(custom-resources): import the AWSLambda package explicitly (#14643) When linking the aws-cdk repository to a CDK app using the `link-all.sh` script, if the app uses `ts-node`, the Lambda code in the @aws-cdk/custom-resources package gets picked up by the TypeScript compiler. That code relied on the `aws-lambda` package being implicitly available, but that would cause `ts-node` to fail. Add an explicit import of it in the code - I checked the only difference in the generated JS code is the sourceMappingUrl, so it shouldn't make a difference at runtime, but allows `ts-node` to load that file successfully. Fixes #11627 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* commit 9a4d624 Author: Oliver Bowman <oliverbowman@protonmail.com> Date: Thu May 13 07:40:55 2021 +0100 docs(lambda-nodejs): Example for esbuild missing comma in property (#13520) ---- Example under esbuild appears to be missing comma. *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
### Description Adds support for `ResultSelector`. [ResultSelector](https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-resultselector) was added to ASL in August 2020 and is currently missing coverage in CDK. This change exposes a new `resultSelector` field to Task, Map, and Parallel state props. This is a JSON object that functions similarly to `Parameters` but where `$` refers to the state's raw result instead of the state input. This allows you to reshape the result without using extra Pass states. The implementation mimics what exists for Parameters. I'm not convinced we need extra types here. #### Example ```ts new tasks.LambdaInvoke(this, 'Invoke Handler', { lambdaFunction: fn, resultSelector: { lambdaOutput: sfn.JsonPath.stringAt('$.Payload'), invokeRequestId: sfn.JsonPath.stringAt('$.SdkResponseMetadata.RequestId'), staticValue: 'foo', }, }) ``` Which produces the following ASL: ```json { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { "FunctionName": ${functionName}, "Payload.$": "$" }, "ResultSelector": { "lambdaOutput.$": "$.Payload", "invokeRequestId.$": "$.SdkResponseMetadata.RequestId", "staticValue": "foo", }, "Next": ${nextState} } ``` ### Testing * Unit tests for Map, Task, and Parallel states to include `resultSelector` * Unit test with ResultSelector for `LambdaInvoke` state updated to include `resultSelector` * Updated LambdaInvoke integ test to use ResultSelector for one of the states. Executed state machine manually through the AWS console to ensure the example actually works too. Closes aws#9904 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
A few weeks ago Step Functions added the ResultSelector Payload Template to the Task, Map and Parallel states. It's still missing from AWS CDK. Some other stuff was added too.
It's possible to use CustomState to write your own state, but that is very complicated to do in practice because many things are no longer automatically generated. It would be helpful if state objects allowed you to easily add custom attributes to the state definition generated by toStateJson().
My temporary solution is to extend the state class with something like this:
The text was updated successfully, but these errors were encountered: