awscdkioteventsactionsalpha

package module
v2.158.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Actions for AWS::IoTEvents Detector Model

---

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 Semantic Versioning 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.


This library contains integration classes to specify actions of state events of Detector Model in @aws-cdk/aws-iotevents-alpha. Instances of these classes should be passed to State defined in @aws-cdk/aws-iotevents-alpha You can define built-in actions to use a timer or set a variable, or send data to other AWS resources.

This library contains integration classes to use a timer or set a variable, or send data to other AWS resources. AWS IoT Events can trigger actions when it detects a specified event or transition event.

Currently supported are:

  • Use timer
  • Set variable to detector instance
  • Invoke a Lambda function

Use timer

The code snippet below creates an Action that creates the timer with duration in seconds.

// Example automatically generated from non-compiling source. May contain errors.
import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import actions "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

var input iInput

state := iotevents.NewState(&StateProps{
	StateName: jsii.String("MyState"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewSetTimerAction(jsii.String("MyTimer"), map[string]interface{}{
					"duration": cdk.Duration_seconds(jsii.Number(60)),
				}),
			},
		},
	},
})

Setting duration by IoT Events Expression:

// Example automatically generated from non-compiling source. May contain errors.
actions.NewSetTimerAction(jsii.String("MyTimer"), map[string]interface{}{
	"durationExpression": iotevents.Expression_inputAttribute(input, jsii.String("payload.durationSeconds")),
})

And the timer can be reset and cleared. Below is an example of general Device HeartBeat Detector Model:

// Example automatically generated from non-compiling source. May contain errors.
online := iotevents.NewState(map[string]interface{}{
	"stateName": jsii.String("Online"),
	"onEnter": []map[string]interface{}{
		map[string]interface{}{
			"eventName": jsii.String("enter-event"),
			"condition": iotevents.Expression_currentInput(input),
			"actions": []interface{}{
				actions.NewSetTimerAction(jsii.String("MyTimer"), map[string]interface{}{
					"duration": cdk.Duration_seconds(jsii.Number(60)),
				}),
			},
		},
	},
	"onInput": []map[string]interface{}{
		map[string]interface{}{
			"eventName": jsii.String("input-event"),
			"condition": iotevents.Expression_currentInput(input),
			"actions": []interface{}{
				actions.NewResetTimerAction(jsii.String("MyTimer")),
			},
		},
	},
	"onExit": []map[string]interface{}{
		map[string]interface{}{
			"eventName": jsii.String("exit-event"),
			"actions": []interface{}{
				actions.NewClearTimerAction(jsii.String("MyTimer")),
			},
		},
	},
})
offline := iotevents.NewState(map[string]*string{
	"stateName": jsii.String("Offline"),
})

online.transitionTo(offline, map[string]interface{}{
	"when": iotevents.Expression_timeout(jsii.String("MyTimer")),
})
offline.transitionTo(online, map[string]interface{}{
	"when": iotevents.Expression_currentInput(input),
})

Set variable to detector instance

The code snippet below creates an Action that set variable to detector instance when it is triggered.

import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import actions "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

var input iInput

state := iotevents.NewState(&StateProps{
	StateName: jsii.String("MyState"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewSetVariableAction(jsii.String("MyVariable"), iotevents.Expression_InputAttribute(input, jsii.String("payload.temperature"))),
			},
		},
	},
})

Invoke a Lambda function

The code snippet below creates an Action that invoke a Lambda function when it is triggered.

import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import actions "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"
import lambda "github.com/aws/aws-cdk-go/awscdk"

var input iInput
var func iFunction

state := iotevents.NewState(&StateProps{
	StateName: jsii.String("MyState"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewLambdaInvokeAction(func),
			},
		},
	},
})

Documentation

Overview

Receipt Detector Model actions for AWS IoT Events

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClearTimerAction_Override

func NewClearTimerAction_Override(c ClearTimerAction, timerName *string)

Experimental.

func NewLambdaInvokeAction_Override

func NewLambdaInvokeAction_Override(l LambdaInvokeAction, func_ awslambda.IFunction)

Experimental.

func NewResetTimerAction_Override

func NewResetTimerAction_Override(r ResetTimerAction, timerName *string)

Experimental.

func NewSetTimerAction_Override

func NewSetTimerAction_Override(s SetTimerAction, timerName *string, timerDuration TimerDuration)

Experimental.

func NewSetVariableAction_Override

func NewSetVariableAction_Override(s SetVariableAction, variableName *string, value awscdkioteventsalpha.Expression)

Experimental.

func NewTimerDuration_Override

func NewTimerDuration_Override(t TimerDuration)

Experimental.

Types

type ClearTimerAction

type ClearTimerAction interface {
	awscdkioteventsalpha.IAction
}

The action to delete an existing timer.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import iotevents_actions_alpha "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

clearTimerAction := iotevents_actions_alpha.NewClearTimerAction(jsii.String("timerName"))

Experimental.

func NewClearTimerAction

func NewClearTimerAction(timerName *string) ClearTimerAction

Experimental.

type LambdaInvokeAction

type LambdaInvokeAction interface {
	awscdkioteventsalpha.IAction
}

The action to write the data to an AWS Lambda function.

Example:

import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"
import lambda "github.com/aws/aws-cdk-go/awscdk"

var func iFunction

input := iotevents.NewInput(this, jsii.String("MyInput"), &InputProps{
	InputName: jsii.String("my_input"),
	 // optional
	AttributeJsonPaths: []*string{
		jsii.String("payload.deviceId"),
		jsii.String("payload.temperature"),
	},
})

warmState := iotevents.NewState(&StateProps{
	StateName: jsii.String("warm"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-enter-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewLambdaInvokeAction(func),
			},
		},
	},
	OnInput: []*event{
		&event{
			 // optional
			EventName: jsii.String("test-input-event"),
			Actions: []*iAction{
				actions.NewLambdaInvokeAction(func),
			},
		},
	},
	OnExit: []*event{
		&event{
			 // optional
			EventName: jsii.String("test-exit-event"),
			Actions: []*iAction{
				actions.NewLambdaInvokeAction(func),
			},
		},
	},
})
coldState := iotevents.NewState(&StateProps{
	StateName: jsii.String("cold"),
})

// transit to coldState when temperature is less than 15
warmState.TransitionTo(coldState, &TransitionOptions{
	EventName: jsii.String("to_coldState"),
	 // optional property, default by combining the names of the States
	When: iotevents.Expression_Lt(iotevents.Expression_InputAttribute(input, jsii.String("payload.temperature")), iotevents.Expression_FromString(jsii.String("15"))),
	Executing: []*iAction{
		actions.NewLambdaInvokeAction(func),
	},
})
// transit to warmState when temperature is greater than or equal to 15
coldState.TransitionTo(warmState, &TransitionOptions{
	When: iotevents.Expression_Gte(iotevents.Expression_*InputAttribute(input, jsii.String("payload.temperature")), iotevents.Expression_*FromString(jsii.String("15"))),
})

iotevents.NewDetectorModel(this, jsii.String("MyDetectorModel"), &DetectorModelProps{
	DetectorModelName: jsii.String("test-detector-model"),
	 // optional
	Description: jsii.String("test-detector-model-description"),
	 // optional property, default is none
	EvaluationMethod: iotevents.EventEvaluation_SERIAL,
	 // optional property, default is iotevents.EventEvaluation.BATCH
	DetectorKey: jsii.String("payload.deviceId"),
	 // optional property, default is none and single detector instance will be created and all inputs will be routed to it
	InitialState: warmState,
})

Experimental.

func NewLambdaInvokeAction

func NewLambdaInvokeAction(func_ awslambda.IFunction) LambdaInvokeAction

Experimental.

type ResetTimerAction

type ResetTimerAction interface {
	awscdkioteventsalpha.IAction
}

The action to reset an existing timer.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import iotevents_actions_alpha "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

resetTimerAction := iotevents_actions_alpha.NewResetTimerAction(jsii.String("timerName"))

Experimental.

func NewResetTimerAction

func NewResetTimerAction(timerName *string) ResetTimerAction

Experimental.

type SetTimerAction

type SetTimerAction interface {
	awscdkioteventsalpha.IAction
}

The action to create a timer with duration in seconds.

Example:

// Example automatically generated from non-compiling source. May contain errors.
import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import actions "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

var input iInput

state := iotevents.NewState(&StateProps{
	StateName: jsii.String("MyState"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewSetTimerAction(jsii.String("MyTimer"), map[string]interface{}{
					"duration": cdk.Duration_seconds(jsii.Number(60)),
				}),
			},
		},
	},
})

Experimental.

func NewSetTimerAction

func NewSetTimerAction(timerName *string, timerDuration TimerDuration) SetTimerAction

Experimental.

type SetVariableAction

type SetVariableAction interface {
	awscdkioteventsalpha.IAction
}

The action to create a variable with a specified value.

Example:

import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import actions "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

var input iInput

state := iotevents.NewState(&StateProps{
	StateName: jsii.String("MyState"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewSetVariableAction(jsii.String("MyVariable"), iotevents.Expression_InputAttribute(input, jsii.String("payload.temperature"))),
			},
		},
	},
})

Experimental.

func NewSetVariableAction

func NewSetVariableAction(variableName *string, value awscdkioteventsalpha.Expression) SetVariableAction

Experimental.

type TimerDuration

type TimerDuration interface {
}

The duration of the timer.

Example:

// Example automatically generated from non-compiling source. May contain errors.
import "github.com/aws/aws-cdk-go/awscdkioteventsalpha"
import actions "github.com/aws/aws-cdk-go/awscdkioteventsactionsalpha"

var input iInput

state := iotevents.NewState(&StateProps{
	StateName: jsii.String("MyState"),
	OnEnter: []event{
		&event{
			EventName: jsii.String("test-event"),
			Condition: iotevents.Expression_CurrentInput(input),
			Actions: []iAction{
				actions.NewSetTimerAction(jsii.String("MyTimer"), map[string]interface{}{
					"duration": cdk.Duration_seconds(jsii.Number(60)),
				}),
			},
		},
	},
})

Experimental.

func TimerDuration_FromDuration

func TimerDuration_FromDuration(duration awscdk.Duration) TimerDuration

Create a timer-duration from Duration.

The range of the duration is 60-31622400 seconds. The evaluated result of the duration expression is rounded down to the nearest whole number. For example, if you set the timer to 60.99 seconds, the evaluated result of the duration expression is 60 seconds. Experimental.

func TimerDuration_FromExpression

func TimerDuration_FromExpression(expression awscdkioteventsalpha.Expression) TimerDuration

Create a timer-duration from Expression.

You can use a string expression that includes numbers, variables ($variable.<variable-name>), and input values ($input.<input-name>.<path-to-datum>) as the duration.

The range of the duration is 60-31622400 seconds. The evaluated result of the duration expression is rounded down to the nearest whole number. For example, if you set the timer to 60.99 seconds, the evaluated result of the duration expression is 60 seconds. Experimental.

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL