awscdkioteventsactionsalpha

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

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 7 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. 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 iotevents "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,
				[]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.

import iotevents "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 NewLambdaInvokeAction_Override

func NewLambdaInvokeAction_Override(l LambdaInvokeAction, func_ awslambda.IFunction)

Experimental.

func NewSetVariableAction_Override

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

Experimental.

Types

type LambdaInvokeAction

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

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

Example:

import iotevents "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 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 {
	awscdkioteventsalpha.IAction
	// Returns the AWS IoT Events action specification.
	// Experimental.
	Bind(_scope constructs.Construct, _options *awscdkioteventsalpha.ActionBindOptions) *awscdkioteventsalpha.ActionConfig
}

The action to create a variable with a specified value.

Example:

// Example automatically generated from non-compiling source. May contain errors.
import iotevents "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,
				[]interface{}{
					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.

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