|
| 1 | +/** |
| 2 | + * Stack verification steps: |
| 3 | + * * put a message |
| 4 | + * * aws iotevents-data batch-put-message --messages=messageId=(date | md5),inputName=test_input,payload=(echo '{"payload":{"temperature":31.9,"deviceId":"000"}}' | base64) |
| 5 | + */ |
| 6 | +import * as iotevents from '@aws-cdk/aws-iotevents'; |
| 7 | +import * as cdk from '@aws-cdk/core'; |
| 8 | +import * as actions from '../../lib'; |
| 9 | + |
| 10 | +class TestStack extends cdk.Stack { |
| 11 | + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { |
| 12 | + super(scope, id, props); |
| 13 | + |
| 14 | + const input = new iotevents.Input(this, 'MyInput', { |
| 15 | + inputName: 'test_input', |
| 16 | + attributeJsonPaths: ['payload.deviceId', 'payload.temperature'], |
| 17 | + }); |
| 18 | + |
| 19 | + const state = new iotevents.State({ |
| 20 | + stateName: 'MyState', |
| 21 | + onEnter: [{ |
| 22 | + eventName: 'enter-event', |
| 23 | + condition: iotevents.Expression.currentInput(input), |
| 24 | + actions: [ |
| 25 | + new actions.SetVariableAction( |
| 26 | + 'MyVariable', |
| 27 | + iotevents.Expression.inputAttribute(input, 'payload.temperature'), |
| 28 | + ), |
| 29 | + ], |
| 30 | + }], |
| 31 | + }); |
| 32 | + |
| 33 | + new iotevents.DetectorModel(this, 'MyDetectorModel', { |
| 34 | + detectorKey: 'payload.deviceId', |
| 35 | + initialState: state, |
| 36 | + }); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +const app = new cdk.App(); |
| 41 | +new TestStack(app, 'iotevents-set-variable-action-test-stack'); |
| 42 | +app.synth(); |
0 commit comments