Skip to content

Commit

Permalink
feat(stepfunctions-tasks): support parameters in StepFunctionsInvokeA…
Browse files Browse the repository at this point in the history
…ctivity (#21077)

Fixes #21020

This PR adds the parameters to the StepFunctionsInvokeActivity class.

----

### 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*
  • Loading branch information
daschaa authored Jul 12, 2022
1 parent a25677b commit 10f8821
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 8 deletions.
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,25 @@ new tasks.StepFunctionsInvokeActivity(this, 'Submit Job', {
});
```

Use the [Parameters](https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters) field to create a collection of key-value pairs that are passed as input.
The values of each can either be static values that you include in your state machine definition, or selected from either the input or the context object with a path.

```ts
const submitJobActivity = new sfn.Activity(this, 'SubmitJob');

new tasks.StepFunctionsInvokeActivity(this, 'Submit Job', {
activity: submitJobActivity,
parameters: {
comment: 'Selecting what I care about.',
MyDetails: {
size: sfn.JsonPath.stringAt('$.product.details.size'),
exists: sfn.JsonPath.stringAt('$.product.availability'),
StaticValue: 'foo'
},
},
});
```

## SQS

Step Functions supports [Amazon SQS](https://docs.aws.amazon.com/step-functions/latest/dg/connect-sqs.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ export interface StepFunctionsInvokeActivityProps extends sfn.TaskStateBaseProps
* Step Functions Activity to invoke
*/
readonly activity: sfn.IActivity

/**
* Parameters pass a collection of key-value pairs, either static values or JSONPath expressions that select from the input.
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters
*
* @default No parameters
*/
readonly parameters?: { [name: string]: any };
}

/**
Expand Down Expand Up @@ -39,6 +48,7 @@ export class StepFunctionsInvokeActivity extends sfn.TaskStateBase {
protected _renderTask(): any {
return {
Resource: this.props.activity.activityArn,
Parameters: this.props.parameters ? sfn.FieldUtils.renderObject(this.props.parameters) : undefined,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class InvokeActivityStack extends cdk.Stack {
const finalStatus = new tasks.StepFunctionsInvokeActivity(this, 'Get Final Job Status', {
activity: checkJobActivity,
inputPath: '$.guid',
parameters: {
'input.$': '$',
'stringArgument': 'inital-task',
'numberArgument': 123,
'booleanArgument': true,
'arrayArgument': ['a', 'b', 'c'],
'jsonPath': sfn.JsonPath.stringAt('$.status'),
},
});

const chain = sfn.Chain
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "20.0.0",
"files": {
"b9edde5b0344ecb8e67455541ca7cae1ee0b7f594b359920852dcb647be6a6f2": {
"source": {
"path": "aws-stepfunctions-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "b9edde5b0344ecb8e67455541ca7cae1ee0b7f594b359920852dcb647be6a6f2.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
{
"Ref": "CheckJob5FFC1D6F"
},
"\"}},\"TimeoutSeconds\":300}"
"\",\"Parameters\":{\"input.$\":\"$\",\"stringArgument\":\"inital-task\",\"numberArgument\":123,\"booleanArgument\":true,\"arrayArgument\":[\"a\",\"b\",\"c\"],\"jsonPath.$\":\"$.status\"}}},\"TimeoutSeconds\":300}"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"17.0.0"}
{"version":"20.0.0"}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "18.0.0",
"version": "20.0.0",
"testCases": {
"aws-stepfunctions-tasks/test/stepfunctions/integ.invoke-activity": {
"stepfunctions/integ.invoke-activity": {
"stacks": [
"aws-stepfunctions-integ"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "17.0.0",
"version": "20.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "@aws-cdk/core.Construct",
"version": "0.0.0"
"fqn": "constructs.Construct",
"version": "10.1.33"
}
},
"aws-stepfunctions-integ": {
Expand Down Expand Up @@ -187,7 +187,7 @@
{
"Ref": "CheckJob5FFC1D6F"
},
"\"}},\"TimeoutSeconds\":300}"
"\",\"Parameters\":{\"input.$\":\"$\",\"stringArgument\":\"inital-task\",\"numberArgument\":123,\"booleanArgument\":true,\"arrayArgument\":[\"a\",\"b\",\"c\"],\"jsonPath.$\":\"$.status\"}}},\"TimeoutSeconds\":300}"
]
]
}
Expand Down

0 comments on commit 10f8821

Please sign in to comment.