Namespace Amazon.CDK.AWS.IoTEvents.Alpha
AWS::IoTEvents Construct Library
---The APIs of higher level constructs in this module are experimental and under active development.
They are subject to non-backward compatible changes or removal in any future version. These are
not subject to the <a href="https://semver.org/">Semantic Versioning</a> model and breaking changes will be
announced in the release notes. This means that while you may use them, you may need to update
your source code when upgrading to a newer version of this package.
AWS IoT Events enables you to monitor your equipment or device fleets for failures or changes in operation, and to trigger actions when such events occur.
DetectorModel
The following example creates an AWS IoT Events detector model to your stack. The detector model need a reference to at least one AWS IoT Events input. AWS IoT Events inputs enable the detector to get MQTT payload values from IoT Core rules.
You can define built-in actions to use a timer or set a variable, or send data to other AWS resources. See also @aws-cdk/aws-iotevents-actions-alpha for other actions.
using Amazon.CDK.AWS.IoTEvents.Alpha;
using Amazon.CDK.AWS.IoTEvents.Actions.Alpha;
using Amazon.CDK.AWS.Lambda;
IFunction func;
var input = new Input(this, "MyInput", new InputProps {
InputName = "my_input", // optional
AttributeJsonPaths = new [] { "payload.deviceId", "payload.temperature" }
});
var warmState = new State(new StateProps {
StateName = "warm",
OnEnter = new [] { new Event {
EventName = "test-enter-event",
Condition = Expression.CurrentInput(input),
Actions = new [] { new LambdaInvokeAction(func) }
} },
OnInput = new [] { new Event { // optional
EventName = "test-input-event",
Actions = new [] { new LambdaInvokeAction(func) } } },
OnExit = new [] { new Event { // optional
EventName = "test-exit-event",
Actions = new [] { new LambdaInvokeAction(func) } } }
});
var coldState = new State(new StateProps {
StateName = "cold"
});
// transit to coldState when temperature is less than 15
warmState.TransitionTo(coldState, new TransitionOptions {
EventName = "to_coldState", // optional property, default by combining the names of the States
When = Expression.Lt(Expression.InputAttribute(input, "payload.temperature"), Expression.FromString("15")),
Executing = new [] { new LambdaInvokeAction(func) }
});
// transit to warmState when temperature is greater than or equal to 15
coldState.TransitionTo(warmState, new TransitionOptions {
When = Expression.Gte(Expression.InputAttribute(input, "payload.temperature"), Expression.FromString("15"))
});
new DetectorModel(this, "MyDetectorModel", new DetectorModelProps {
DetectorModelName = "test-detector-model", // optional
Description = "test-detector-model-description", // optional property, default is none
EvaluationMethod = EventEvaluation.SERIAL, // optional property, default is iotevents.EventEvaluation.BATCH
DetectorKey = "payload.deviceId", // optional property, default is none and single detector instance will be created and all inputs will be routed to it
InitialState = warmState
});
To grant permissions to put messages in the input,
you can use the grantWrite()
method:
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.IoTEvents.Alpha;
IGrantable grantable;
var input = Input.FromInputName(this, "MyInput", "my_input");
input.GrantWrite(grantable);
Classes
ActionBindOptions | (experimental) Options when binding a Action to a detector model. |
ActionConfig | (experimental) Properties for a AWS IoT Events action. |
DetectorModel | (experimental) Defines an AWS IoT Events detector model in this stack. |
DetectorModelProps | (experimental) Properties for defining an AWS IoT Events detector model. |
Event | (experimental) Specifies the actions to be performed when the condition evaluates to |
EventEvaluation | (experimental) Information about the order in which events are evaluated and how actions are executed. |
Expression | (experimental) Expression for events in Detector Model state. |
Input | (experimental) Defines an AWS IoT Events input in this stack. |
InputProps | (experimental) Properties for defining an AWS IoT Events input. |
State | (experimental) Defines a state of a detector. |
StateProps | (experimental) Properties for defining a state of a detector. |
TransitionOptions | (experimental) Properties for options of state transition. |
Interfaces
IAction | (experimental) An abstract action for DetectorModel. |
IActionBindOptions | (experimental) Options when binding a Action to a detector model. |
IActionConfig | (experimental) Properties for a AWS IoT Events action. |
IDetectorModel | (experimental) Represents an AWS IoT Events detector model. |
IDetectorModelProps | (experimental) Properties for defining an AWS IoT Events detector model. |
IEvent | (experimental) Specifies the actions to be performed when the condition evaluates to |
IInput | (experimental) Represents an AWS IoT Events input. |
IInputProps | (experimental) Properties for defining an AWS IoT Events input. |
IStateProps | (experimental) Properties for defining a state of a detector. |
ITransitionOptions | (experimental) Properties for options of state transition. |