-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathiotsitewise-basics.js
More file actions
695 lines (646 loc) · 23.1 KB
/
iotsitewise-basics.js
File metadata and controls
695 lines (646 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[iotsitewise.JavaScript.Basics.scenario]
import {
Scenario,
ScenarioAction,
ScenarioInput,
ScenarioOutput,
//} from "@aws-doc-sdk-examples/lib/scenario/index.js";
} from "../../libs/scenario/index.js";
import {
IoTSiteWiseClient,
CreateAssetModelCommand,
CreateAssetCommand,
ListAssetModelPropertiesCommand,
BatchPutAssetPropertyValueCommand,
GetAssetPropertyValueCommand,
CreatePortalCommand,
DescribePortalCommand,
CreateGatewayCommand,
DescribeGatewayCommand,
DeletePortalCommand,
DeleteGatewayCommand,
DeleteAssetCommand,
DeleteAssetModelCommand,
DescribeAssetModelCommand,
} from "@aws-sdk/client-iotsitewise";
import {
CloudFormationClient,
CreateStackCommand,
DeleteStackCommand,
DescribeStacksCommand,
waitUntilStackExists,
waitUntilStackCreateComplete,
waitUntilStackDeleteComplete,
} from "@aws-sdk/client-cloudformation";
import { wait } from "@aws-doc-sdk-examples/lib/utils/util-timers.js";
import { parseArgs } from "node:util";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname } from "node:path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const stackName = "SiteWiseBasicsStack";
/**
* @typedef {{
* iotSiteWiseClient: import('@aws-sdk/client-iotsitewise').IotSiteWiseClient,
* cloudFormationClient: import('@aws-sdk/client-cloudformation').CloudFormationClient,
* stackName,
* stack,
* askToDeleteResources: true,
* asset: {assetName: "MyAsset1"},
* assetModel: {assetModelName: "MyAssetModel1"},
* portal: {portalName: "MyPortal1"},
* gateway: {gatewayName: "MyGateway1"},
* propertyIds: [],
* contactEmail: "user@mydomain.com",
* thing: "MyThing1",
* sampleData: { temperature: 23.5, humidity: 65.0}
* }} State
*/
/**
* Used repeatedly to have the user press enter.
* @type {ScenarioInput}
*/
const pressEnter = new ScenarioInput("continue", "Press Enter to continue", {
type: "confirm",
});
const greet = new ScenarioOutput(
"greet",
`AWS IoT SiteWise is a fully managed industrial software-as-a-service (SaaS) that makes it easy to collect, store, organize, and monitor data from industrial equipment and processes. It is designed to help industrial and manufacturing organizations collect data from their equipment and processes, and use that data to make informed decisions about their operations.
One of the key features of AWS IoT SiteWise is its ability to connect to a wide range of industrial equipment and systems, including programmable logic controllers (PLCs), sensors, and other industrial devices. It can collect data from these devices and organize it into a unified data model, making it easier to analyze and gain insights from the data. AWS IoT SiteWise also provides tools for visualizing the data, setting up alarms and alerts, and generating reports.
Another key feature of AWS IoT SiteWise is its ability to scale to handle large volumes of data. It can collect and store data from thousands of devices and process millions of data points per second, making it suitable for large-scale industrial operations. Additionally, AWS IoT SiteWise is designed to be secure and compliant, with features like role-based access controls, data encryption, and integration with other AWS services for additional security and compliance features.
Let's get started...`,
{ header: true },
);
const displayBuildCloudFormationStack = new ScenarioOutput(
"displayBuildCloudFormationStack",
"This scenario uses AWS CloudFormation to create an IAM role that is required for this scenario. The stack will now be deployed.",
);
const sdkBuildCloudFormationStack = new ScenarioAction(
"sdkBuildCloudFormationStack",
async (/** @type {State} */ state) => {
try {
const data = readFileSync(
`${__dirname}/../../../../resources/cfn/iotsitewise_basics/SitewiseRoles-template.yml`,
"utf8",
);
await state.cloudFormationClient.send(
new CreateStackCommand({
StackName: stackName,
TemplateBody: data,
Capabilities: ["CAPABILITY_IAM"],
}),
);
await waitUntilStackExists(
{ client: state.cloudFormationClient },
{ StackName: stackName },
);
await waitUntilStackCreateComplete(
{ client: state.cloudFormationClient },
{ StackName: stackName },
);
const stack = await state.cloudFormationClient.send(
new DescribeStacksCommand({
StackName: stackName,
}),
);
state.stack = stack.Stacks[0].Outputs[0];
console.log(`The ARN of the IAM role is ${state.stack.OutputValue}`);
} catch (caught) {
console.error(caught.message);
throw caught;
}
},
);
const displayCreateAWSSiteWiseAssetModel = new ScenarioOutput(
"displayCreateAWSSiteWiseAssetModel",
`1. Create an AWS SiteWise Asset Model
An AWS IoT SiteWise Asset Model is a way to represent the physical assets, such as equipment, processes, and systems, that exist in an industrial environment. This model provides a structured and hierarchical representation of these assets, allowing users to define the relationships and properties of each asset.
This scenario creates two asset model properties: temperature and humidity.`,
);
const sdkCreateAWSSiteWiseAssetModel = new ScenarioAction(
"sdkCreateAWSSiteWiseAssetModel",
async (/** @type {State} */ state) => {
let assetModelResponse;
try {
assetModelResponse = await state.iotSiteWiseClient.send(
new CreateAssetModelCommand({
assetModelName: state.assetModel.assetModelName,
assetModelProperties: [
{
name: "Temperature",
dataType: "DOUBLE",
type: {
measurement: {},
},
},
{
name: "Humidity",
dataType: "DOUBLE",
type: {
measurement: {},
},
},
],
}),
);
state.assetModel.assetModelId = assetModelResponse.assetModelId;
console.log(
`Asset Model successfully created. Asset Model ID: ${state.assetModel.assetModelId}`,
);
} catch (caught) {
if (caught.name === "ResourceAlreadyExistsException") {
console.log(
`The Asset Model ${state.assetModel.assetModelName} already exists.`,
);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayCreateAWSIoTSiteWiseAssetModel = new ScenarioOutput(
"displayCreateAWSIoTSiteWiseAssetModel",
`2. Create an AWS IoT SiteWise Asset
The IoT SiteWise model that we just created defines the structure and metadata for your physical assets. Now we create an asset from the asset model.
Let's wait 30 seconds for the asset to be ready.`,
);
const waitThirtySeconds = new ScenarioAction("waitThirtySeconds", async () => {
await wait(30); // wait 30 seconds
console.log("Time's up! Let's check the asset's status.");
});
const sdkCreateAWSIoTSiteWiseAssetModel = new ScenarioAction(
"sdkCreateAWSIoTSiteWiseAssetModel",
async (/** @type {State} */ state) => {
try {
const assetResponse = await state.iotSiteWiseClient.send(
new CreateAssetCommand({
assetModelId: state.assetModel.assetModelId,
assetName: state.asset.assetName,
}),
);
state.asset.assetId = assetResponse.assetId;
console.log(`Asset created with ID: ${state.asset.assetId}`);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(
`The Asset ${state.assetModel.assetModelName} was not found.`,
);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayRetrievePropertyId = new ScenarioOutput(
"displayRetrievePropertyId",
`3. Retrieve the property ID values
To send data to an asset, we need to get the property ID values. In this scenario, we access the temperature and humidity property ID values.`,
);
const sdkRetrievePropertyId = new ScenarioAction(
"sdkRetrievePropertyId",
async (state) => {
try {
const retrieveResponse = await state.iotSiteWiseClient.send(
new ListAssetModelPropertiesCommand({
assetModelId: state.assetModel.assetModelId,
}),
);
for (const retrieveResponseKey in retrieveResponse.assetModelPropertySummaries) {
if (
retrieveResponse.assetModelPropertySummaries[retrieveResponseKey]
.name === "Humidity"
) {
state.propertyIds.Humidity =
retrieveResponse.assetModelPropertySummaries[
retrieveResponseKey
].id;
}
if (
retrieveResponse.assetModelPropertySummaries[retrieveResponseKey]
.name === "Temperature"
) {
state.propertyIds.Temperature =
retrieveResponse.assetModelPropertySummaries[
retrieveResponseKey
].id;
}
}
console.log(`The Humidity propertyId is ${state.propertyIds.Humidity}`);
console.log(
`The Temperature propertyId is ${state.propertyIds.Temperature}`,
);
} catch (caught) {
if (caught.name === "IoTSiteWiseException") {
console.log(
`There was a problem retrieving the properties: ${caught.message}`,
);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displaySendDataToIoTSiteWiseAsset = new ScenarioOutput(
"displaySendDataToIoTSiteWiseAsset",
`4. Send data to an AWS IoT SiteWise Asset
By sending data to an IoT SiteWise Asset, you can aggregate data from multiple sources, normalize the data into a standard format, and store it in a centralized location. This makes it easier to analyze and gain insights from the data.
In this example, we generate sample temperature and humidity data and send it to the AWS IoT SiteWise asset.`,
);
const sdkSendDataToIoTSiteWiseAsset = new ScenarioAction(
"sdkSendDataToIoTSiteWiseAsset",
async (state) => {
try {
const sendResponse = await state.iotSiteWiseClient.send(
new BatchPutAssetPropertyValueCommand({
entries: [
{
entryId: "entry-3",
assetId: state.asset.assetId,
propertyId: state.propertyIds.Humidity,
propertyValues: [
{
value: {
doubleValue: state.sampleData.humidity,
},
timestamp: {
timeInSeconds: Math.floor(Date.now() / 1000),
},
},
],
},
{
entryId: "entry-4",
assetId: state.asset.assetId,
propertyId: state.propertyIds.Temperature,
propertyValues: [
{
value: {
doubleValue: state.sampleData.temperature,
},
timestamp: {
timeInSeconds: Math.floor(Date.now() / 1000),
},
},
],
},
],
}),
);
console.log("The data was sent successfully.");
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Asset ${state.asset.assetName} was not found.`);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayRetrieveValueOfIoTSiteWiseAsset = new ScenarioOutput(
"displayRetrieveValueOfIoTSiteWiseAsset",
`5. Retrieve the value of the IoT SiteWise Asset property
IoT SiteWise is an AWS service that allows you to collect, process, and analyze industrial data from connected equipment and sensors. One of the key benefits of reading an IoT SiteWise property is the ability to gain valuable insights from your industrial data.`,
);
const sdkRetrieveValueOfIoTSiteWiseAsset = new ScenarioAction(
"sdkRetrieveValueOfIoTSiteWiseAsset",
async (/** @type {State} */ state) => {
try {
const temperatureResponse = await state.iotSiteWiseClient.send(
new GetAssetPropertyValueCommand({
assetId: state.asset.assetId,
propertyId: state.propertyIds.Temperature,
}),
);
const humidityResponse = await state.iotSiteWiseClient.send(
new GetAssetPropertyValueCommand({
assetId: state.asset.assetId,
propertyId: state.propertyIds.Humidity,
}),
);
console.log(
`The property value for Temperature is ${temperatureResponse.propertyValue.value.doubleValue}`,
);
console.log(
`The property value for Humidity is ${humidityResponse.propertyValue.value.doubleValue}`,
);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Asset ${state.asset.assetName} was not found.`);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayCreateIoTSiteWisePortal = new ScenarioOutput(
"displayCreateIoTSiteWisePortal",
`6. Create an IoT SiteWise Portal
An IoT SiteWise Portal allows you to aggregate data from multiple industrial sources, such as sensors, equipment, and control systems, into a centralized platform.`,
);
const sdkCreateIoTSiteWisePortal = new ScenarioAction(
"sdkCreateIoTSiteWisePortal",
async (/** @type {State} */ state) => {
try {
const createPortalResponse = await state.iotSiteWiseClient.send(
new CreatePortalCommand({
portalName: state.portal.portalName,
portalContactEmail: state.contactEmail,
roleArn: state.stack.OutputValue,
}),
);
state.portal = { ...state.portal, ...createPortalResponse };
await wait(5); // Allow the portal to properly propagate.
console.log(
`Portal created successfully. Portal ID ${createPortalResponse.portalId}`,
);
} catch (caught) {
if (caught.name === "IoTSiteWiseException") {
console.log(
`There was a problem creating the Portal: ${caught.message}.`,
);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayDescribePortal = new ScenarioOutput(
"displayDescribePortal",
`7. Describe the Portal
In this step, we get a description of the portal and display the portal URL.`,
);
const sdkDescribePortal = new ScenarioAction(
"sdkDescribePortal",
async (/** @type {State} */ state) => {
try {
const describePortalResponse = await state.iotSiteWiseClient.send(
new DescribePortalCommand({
portalId: state.portal.portalId,
}),
);
console.log(`Portal URL: ${describePortalResponse.portalStartUrl}`);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Portal ${state.portal.portalName} was not found.`);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayCreateIoTSiteWiseGateway = new ScenarioOutput(
"displayCreateIoTSiteWiseGateway",
`8. Create an IoT SiteWise Gateway
IoT SiteWise Gateway serves as the bridge between industrial equipment, sensors, and the cloud-based IoT SiteWise service. It is responsible for securely collecting, processing, and transmitting data from various industrial assets to the IoT SiteWise platform, enabling real-time monitoring, analysis, and optimization of industrial operations.`,
);
const sdkCreateIoTSiteWiseGateway = new ScenarioAction(
"sdkCreateIoTSiteWiseGateway",
async (/** @type {State} */ state) => {
try {
const createGatewayResponse = await state.iotSiteWiseClient.send(
new CreateGatewayCommand({
gatewayName: state.gateway.gatewayName,
gatewayPlatform: {
greengrassV2: {
coreDeviceThingName: state.thing,
},
},
}),
);
console.log(
`Gateway creation completed successfully. ID is ${createGatewayResponse.gatewayId}`,
);
state.gateway.gatewayId = createGatewayResponse.gatewayId;
} catch (caught) {
if (caught.name === "IoTSiteWiseException") {
console.log(
`There was a problem creating the gateway: ${caught.message}.`,
);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const displayDescribeIoTSiteWiseGateway = new ScenarioOutput(
"displayDescribeIoTSiteWiseGateway",
"9. Describe the IoT SiteWise Gateway",
);
const sdkDescribeIoTSiteWiseGateway = new ScenarioAction(
"sdkDescribeIoTSiteWiseGateway",
async (/** @type {State} */ state) => {
try {
const describeGatewayResponse = await state.iotSiteWiseClient.send(
new DescribeGatewayCommand({
gatewayId: state.gateway.gatewayId,
}),
);
console.log("Gateway creation completed successfully.");
console.log(`Gateway Name: ${describeGatewayResponse.gatewayName}`);
console.log(`Gateway ARN: ${describeGatewayResponse.gatewayArn}`);
console.log(
`Gateway Platform: ${Object.keys(describeGatewayResponse.gatewayPlatform)}`,
);
console.log(
`Gateway Creation Date: ${describeGatewayResponse.creationDate}`,
);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Gateway ${state.gateway.gatewayId} was not found.`);
throw caught;
}
console.error(`${caught.message}`);
throw caught;
}
},
);
const askToDeleteResources = new ScenarioInput(
"askToDeleteResources",
`10. Delete the AWS IoT SiteWise Assets
Before you can delete the Asset Model, you must delete the assets.`,
{ type: "confirm" },
);
const displayConfirmDeleteResources = new ScenarioAction(
"displayConfirmDeleteResources",
async (/** @type {State} */ state) => {
if (state.askToDeleteResources) {
return "You selected to delete the SiteWise assets.";
}
return "The resources will not be deleted. Please delete them manually to avoid charges.";
},
);
const sdkDeleteResources = new ScenarioAction(
"sdkDeleteResources",
async (/** @type {State} */ state) => {
await wait(10); // Give the portal status time to catch up.
try {
await state.iotSiteWiseClient.send(
new DeletePortalCommand({
portalId: state.portal.portalId,
}),
);
console.log(
`Portal ${state.portal.portalName} was deleted successfully.`,
);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Portal ${state.portal.portalName} was not found.`);
} else {
console.log(`When trying to delete the portal: ${caught.message}`);
}
}
try {
await state.iotSiteWiseClient.send(
new DeleteGatewayCommand({
gatewayId: state.gateway.gatewayId,
}),
);
console.log(
`Gateway ${state.gateway.gatewayName} was deleted successfully.`,
);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Gateway ${state.gateway.gatewayId} was not found.`);
} else {
console.log(`When trying to delete the gateway: ${caught.message}`);
}
}
try {
await state.iotSiteWiseClient.send(
new DeleteAssetCommand({
assetId: state.asset.assetId,
}),
);
await wait(5); // Allow the delete to finish.
console.log(`Asset ${state.asset.assetName} was deleted successfully.`);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(`The Asset ${state.asset.assetName} was not found.`);
} else {
console.log(`When deleting the asset: ${caught.message}`);
}
}
await wait(30); // Allow asset deletion to finish.
try {
await state.iotSiteWiseClient.send(
new DeleteAssetModelCommand({
assetModelId: state.assetModel.assetModelId,
}),
);
console.log(
`Asset Model ${state.assetModel.assetModelName} was deleted successfully.`,
);
} catch (caught) {
if (caught.name === "ResourceNotFoundException") {
console.log(
`The Asset Model ${state.assetModel.assetModelName} was not found.`,
);
} else {
console.log(`When deleting the asset model: ${caught.message}`);
}
}
try {
await state.cloudFormationClient.send(
new DeleteStackCommand({
StackName: stackName,
}),
);
await waitUntilStackDeleteComplete(
{ client: state.cloudFormationClient },
{ StackName: stackName },
);
console.log("The stack was deleted successfully.");
} catch (caught) {
console.log(
`${caught.message}. The stack was NOT deleted. Please clean up the resources manually.`,
);
}
},
{ skipWhen: (/** @type {{}} */ state) => !state.askToDeleteResources },
);
const goodbye = new ScenarioOutput(
"goodbye",
"This concludes the IoT Sitewise Basics scenario for the AWS Javascript SDK v3. Thank you!",
);
const myScenario = new Scenario(
"IoTSiteWise Basics",
[
greet,
pressEnter,
displayBuildCloudFormationStack,
sdkBuildCloudFormationStack,
pressEnter,
displayCreateAWSSiteWiseAssetModel,
sdkCreateAWSSiteWiseAssetModel,
displayCreateAWSIoTSiteWiseAssetModel,
pressEnter,
waitThirtySeconds,
sdkCreateAWSIoTSiteWiseAssetModel,
pressEnter,
displayRetrievePropertyId,
sdkRetrievePropertyId,
pressEnter,
displaySendDataToIoTSiteWiseAsset,
sdkSendDataToIoTSiteWiseAsset,
pressEnter,
displayRetrieveValueOfIoTSiteWiseAsset,
sdkRetrieveValueOfIoTSiteWiseAsset,
pressEnter,
displayCreateIoTSiteWisePortal,
sdkCreateIoTSiteWisePortal,
pressEnter,
displayDescribePortal,
sdkDescribePortal,
pressEnter,
displayCreateIoTSiteWiseGateway,
sdkCreateIoTSiteWiseGateway,
pressEnter,
displayDescribeIoTSiteWiseGateway,
sdkDescribeIoTSiteWiseGateway,
pressEnter,
askToDeleteResources,
displayConfirmDeleteResources,
sdkDeleteResources,
goodbye,
],
{
iotSiteWiseClient: new IoTSiteWiseClient({}),
cloudFormationClient: new CloudFormationClient({}),
asset: { assetName: "MyAsset1" },
assetModel: { assetModelName: "MyAssetModel1" },
portal: { portalName: "MyPortal1" },
gateway: { gatewayName: "MyGateway1" },
propertyIds: [],
contactEmail: "user@mydomain.com",
thing: "MyThing1",
sampleData: { temperature: 23.5, humidity: 65.0 },
},
);
/** @type {{ stepHandlerOptions: StepHandlerOptions }} */
export const main = async (stepHandlerOptions) => {
await myScenario.run(stepHandlerOptions);
};
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const { values } = parseArgs({
options: {
yes: {
type: "boolean",
short: "y",
},
},
});
main({ confirmAll: values.yes });
}
// snippet-end:[iotsitewise.JavaScript.Basics.scenario]