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

feat(step-functions): support parameters option #1492

Merged
merged 2 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export interface StateProps {
*/
inputPath?: string;

/**
* 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
*/
parameters?: { [name: string]: any };

/**
* JSONPath expression to select part of the state to be the output to this state.
*
Expand Down Expand Up @@ -112,6 +122,7 @@ export abstract class State extends cdk.Construct implements IChainable {
// pragmatic!
protected readonly comment?: string;
protected readonly inputPath?: string;
protected readonly parameters?: object;
protected readonly outputPath?: string;
protected readonly resultPath?: string;
protected readonly branches: StateGraph[] = [];
Expand Down Expand Up @@ -144,6 +155,7 @@ export abstract class State extends cdk.Construct implements IChainable {

this.comment = props.comment;
this.inputPath = props.inputPath;
this.parameters = props.parameters;
this.outputPath = props.outputPath;
this.resultPath = props.resultPath;
}
Expand Down Expand Up @@ -297,11 +309,12 @@ export abstract class State extends cdk.Construct implements IChainable {
}

/**
* Render InputPath/OutputPath in ASL JSON format
* Render InputPath/Parameters/OutputPath in ASL JSON format
*/
protected renderInputOutput(): any {
return {
InputPath: renderJsonPath(this.inputPath),
Parameters: this.parameters,
OutputPath: renderJsonPath(this.outputPath),
};
}
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/lib/states/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export interface TaskProps {
*/
inputPath?: string;

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

/**
* JSONPath expression to select part of the state to be the output to this state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,48 @@ export = {
statistic: 'Sum'
});

test.done();
},

'Task should render InputPath / Parameters / OutputPath correctly'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const task = new stepfunctions.Task(stack, 'Task', {
resource: new FakeResource(),
inputPath: "$",
outputPath: "$.state",
parameters: {
"input.$": "$",
"stringArgument": "inital-task",
"numberArgument": 123,
"booleanArgument": true,
"arrayArgument": ["a", "b", "c"]
}
});

// WHEN
const taskState = task.toStateJson();

// THEN
test.deepEqual(taskState, { End: true,
Retry: undefined,
Catch: undefined,
InputPath: '$',
Parameters:
{ 'input.$': '$',
'stringArgument': 'inital-task',
'numberArgument': 123,
'booleanArgument': true,
'arrayArgument': [ 'a', 'b', 'c' ] },
OutputPath: '$.state',
Type: 'Task',
Comment: undefined,
Resource: 'resource',
ResultPath: undefined,
TimeoutSeconds: undefined,
HeartbeatSeconds: undefined
});

test.done();
}
};
Expand Down