(iotevents): add aws-iotevents DetectorModel L2 Construct #17711
Closed
Description
Description
Now, @aws-cdk/aws-iotevents
has no L2 Construct. I will implements L2 Constructs.
Use Case
When users create IoT Events DetectorModel, This Cunstruct will support it.
Proposed Solution
We can create L2 constructs for aws-iotevents.
Other information
I'm starting to design.
And in first PR, I'm going to commit DetectorModel
and State
with only required properties.
Acknowledge
- I may be able to implement this feature request
- This feature might incur a breaking change
Design
ref: CloudFormation
usage:
const timer = new iotevents.Timer("heartbeatTimer", 60);
// Define nodes of the state machine
const onlineState = new iotevents.State({
stateName: "online",
onEnterEvents: [
{
eventName: "setTimer",
actions: [timer.set()], // `timer.set()` return `SetTimerAction`
},
],
onInputEvents: [
{
eventName: "resetTimer",
condition: 'currentInput("HeartbeatInputData")',
actions: [timer.reset()], // `timer.reset()` return `ResetTimerAction`
},
],
});
const offlineState = new iotevents.State({
stateName: "offline",
});
// Define edges of the state machine
onlineState.transitionTo({
eventName: "to_offline",
condition: timer.timeout(), // `timer.timeout()` return just string
nextState: offlineState,
});
offlineState.transitionTo({
eventName: "to_online",
condition: 'currentInput("HeartbeatInputData")',
nextState: onlineState,
});
// Define the state machine
new iotevents.DetectorModel(this, "DetectorModel", {
initialState: onlineState,
});
DetectorModel:
class DetectorModel {
constructor(private readonly initialState: State) {}
private getDefinition() {
const stateSet = this.initialState.getGraphStates();
return {
initialState: this.initialState.stateName,
states: Array.from(stateSet).map((state) => state.toCfn()),
};
}
}
State:
class State {
constructor(private readonly props: StateProps) {}
/**
* get states recursively
*/
getGraphStates(stateSet: Set<State> = new Set<State>()): Set<State> {
if (stateSet.has(this)) {
return stateSet;
}
stateSet.add(this);
const nextStates = initialState.transitionEvents.forEach((te) => {
te.nextState.getGraphStates(stateSet);
});
return stateSet;
}
}
graph:
Roadmap
- implement
DetectorModel
andState
with only required properties- It will not be able to have multiple states yet.
- implement
state.transitionTo()
- It will be able to have multiple states and to transit.
- It will not be able to have events that is without transition.
- It will not be able to perform actions.
- implement
IAction
- create new repository
aws-iotevents-actions
- Note: AWS IoT Events has many actions like AWS IoT TopicRule. https://docs.aws.amazon.com/iotevents/latest/apireference/API_Action.html
- implement
onInput
andonExit
- implement rest Expressions
- implement some actions (separate PRs for each actions)
- It will be able to perform actions.