Skip to content

Commit

Permalink
feat(step-functions): support parameters option (#1492)
Browse files Browse the repository at this point in the history
AWS Step Functions released support for 'Parameters' option in the input definition.

Closes #1480
  • Loading branch information
guisrx authored and rix0rrr committed Jan 8, 2019
1 parent 2169015 commit 935054a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
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.
*
* @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

0 comments on commit 935054a

Please sign in to comment.