awsioteventsactions

package
v1.204.0-devpreview Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Actions for AWS::IoTEvents Detector Model

This library contains integration classes to specify actions of state events of Detector Model in @aws-cdk/aws-iotevents. Instances of these classes should be passed to State defined in @aws-cdk/aws-iotevents 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:

  • Set variable to detector instanse
  • Invoke a Lambda function

Set variable to detector instanse

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

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

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,
				[]interface{}{
					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.

// Example automatically generated from non-compiling source. May contain errors.
import "github.com/aws/aws-cdk-go/awscdk"
import actions "github.com/aws/aws-cdk-go/awscdk"
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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLambdaInvokeAction_Override

func NewLambdaInvokeAction_Override(l LambdaInvokeAction, func_ awslambda.IFunction)

Experimental.

func NewSetVariableAction_Override

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

Experimental.

Types

type LambdaInvokeAction

type LambdaInvokeAction interface {
	awsiotevents.IAction
	// Returns the AWS IoT Events action specification.
	// Experimental.
	Bind(_scope constructs.Construct, options *awsiotevents.ActionBindOptions) *awsiotevents.ActionConfig
}

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

Example:

import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
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 SetVariableAction

type SetVariableAction interface {
	awsiotevents.IAction
	// Returns the AWS IoT Events action specification.
	// Experimental.
	Bind(_scope constructs.Construct, _options *awsiotevents.ActionBindOptions) *awsiotevents.ActionConfig
}

The action to create a variable with a specified value.

Example:

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

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,
				[]interface{}{
					actions.NewSetVariableAction(jsii.String("MyVariable"), iotevents.Expression_InputAttribute(input, jsii.String("payload.temperature"))),
				},
			},
		},
	},
})

Experimental.

func NewSetVariableAction

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

Experimental.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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