question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(iotevents): add aws-iotevents DetectorModel L2 Construct

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
skinny85commented, Feb 2, 2022

Nah, let’s just keep this open then, no need to create new issues for this 🙂.

1reaction
skinny85commented, Nov 30, 2021

OK, makes sense 🙂. Looks good to me, feel free to start working on the implementation based on that design.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class DetectorModel (construct) · AWS CDK
Defines an AWS IoT Events detector model in this stack. Example. import * as iotevents from '@aws-cdk/aws-iotevents ...
Read more >
[NEW LAUNCH!] Introducing AWS IoT Events (IOT367)
AWS IoT Events is a new IoT-managed service that allows enterprises with large operations dependent on IoT devices to continuously monitor ...
Read more >
IoTEvents — Boto3 Docs 1.26.30 documentation - Amazon AWS
For more information, see Create an alarm model in the AWS IoT Events ... Sends an AWS IoT Events input, passing in information...
Read more >
A No-Nonsense Guide To AWS Cloud Development Kit (CDK)
The next level, curated or L2, provides constructs with common ... addLifeCycleRule() , which adds a lifecycle rule to the bucket.
Read more >
Lab 70 - AWS IoT Events
Log into the AWS IoT Events Console; Click on Create detector model. Create detector ... In the Add OnEnter event page, enter Event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found