Skip to content

(iotevents): add aws-iotevents DetectorModel L2 Construct #17711

Closed
@yamatatsu

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:

image

image

Roadmap

  1. implement DetectorModel and State with only required properties
    • It will not be able to have multiple states yet.
  2. 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.
  3. implement IAction
  4. create new repository aws-iotevents-actions
  5. implement onInput and onExit
  6. implement rest Expressions
  7. implement some actions (separate PRs for each actions)
    • It will be able to perform actions.

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ioteventsRelated to AWS IoT Eventsclosed-for-stalenessThis issue was automatically closed because it hadn't received any attention in a while.effort/largeLarge work item – several weeks of effortfeature-requestA feature should be added or improved.feature/new-constructA request for a new L2 constructin-progressThis issue is being actively worked on.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions