Skip to content

Commit

Permalink
fix(stepfunctions): Choice state does not allow state input as a cond…
Browse files Browse the repository at this point in the history
…ition (aws#8991)

Choice state Conditions are currently restricted to variables that must start
with $. or $[, however, the state input of $ is also valid.

Conditions evaluate against strings. Currently, we only allow attributes in the 
state input, but not the entire state input. The state input can be an object or
a plain string (i.e. "No messages").

This change relaxes the validation on the Condition to allow the state input
'$' to be supplied. This allows a string in a state input to be used in a condition
when using Choice states


Closes aws#8990

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
shivlaks authored and Curtis Eppel committed Aug 11, 2020
1 parent 03be0f3 commit 3de9359
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-stepfunctions/lib/condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ enum CompoundOperator {
class VariableComparison extends Condition {
constructor(private readonly variable: string, private readonly comparisonOperator: ComparisonOperator, private readonly value: any) {
super();
if (!/^\$[.[]/.test(variable)) {
throw new Error(`Variable reference must start with '$.' or '$[', got '${variable}'`);
if (!/^\$|(\$[.[])/.test(variable)) {
throw new Error(`Variable reference must be '$', start with '$.', or start with '$[', got '${variable}'`);
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/test/condition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ describe('Condition Variables', () => {
test('Condition variables can start with $[', () => {
expect(() => stepfunctions.Condition.stringEquals('$[0]', 'a')).not.toThrow();
}),
test('Condition variables can reference the state input $', () => {
expect(() => stepfunctions.Condition.stringEquals('$', 'a')).not.toThrow();
}),
test('NotConditon must render properly', () => {
assertRendersTo(stepfunctions.Condition.not(stepfunctions.Condition.stringEquals('$.a', 'b')), { Not: { Variable: '$.a', StringEquals: 'b' } });
}),
Expand Down

0 comments on commit 3de9359

Please sign in to comment.