Skip to content

Commit

Permalink
fix(aws-stepfunctions): explicitly implement IEventRuleTarget
Browse files Browse the repository at this point in the history
So that Java/.NET users can trigger StateMachine from CWE.

Fixes part of #1275.
  • Loading branch information
rix0rrr committed Jan 18, 2019
1 parent 74a2900 commit c51f342
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface StateMachineProps {
/**
* Define a StepFunctions State Machine
*/
export class StateMachine extends cdk.Construct implements IStateMachine {
export class StateMachine extends cdk.Construct implements IStateMachine, events.IEventRuleTarget {
/**
* Import a state machine
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert';
import events = require('@aws-cdk/aws-events');
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
Expand Down Expand Up @@ -134,7 +135,36 @@ export = {
});

test.done();
}
},

'State machine can be used as Event Rule target'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const rule = new events.EventRule(stack, 'Rule', {
scheduleExpression: 'rate(1 minute)'
});
const stateMachine = new stepfunctions.StateMachine(stack, 'SM', {
definition: new stepfunctions.Wait(stack, 'Hello', { })
});

// WHEN
rule.addTarget(stateMachine, {
jsonTemplate: { SomeParam: 'SomeValue' },
});

// THEN
expect(stack).to(haveResourceLike('AWS::Events::Rule', {
Targets: [
{
InputTransformer: {
InputTemplate: "{\"SomeParam\":\"SomeValue\"}"
},
}
]
}));

test.done();
},
};

class FakeResource implements stepfunctions.IStepFunctionsTaskResource {
Expand Down

0 comments on commit c51f342

Please sign in to comment.