forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-asset.js
More file actions
51 lines (48 loc) · 1.42 KB
/
create-asset.js
File metadata and controls
51 lines (48 loc) · 1.42 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[iotsitewise.JavaScript.Basics.createAsset]
import {
CreateAssetCommand,
IoTSiteWiseClient,
} from "@aws-sdk/client-iotsitewise";
import { parseArgs } from "node:util";
/**
* Create an Asset.
* @param {{ assetName : string, assetModelId: string }}
*/
export const main = async ({ assetName, assetModelId }) => {
const client = new IoTSiteWiseClient({});
try {
const result = await client.send(
new CreateAssetCommand({
assetName: assetName, // The name to give the Asset.
assetModelId: assetModelId, // The ID of the asset model from which to create the asset.
}),
);
console.log("Asset created successfully.");
return result;
} catch (caught) {
if (caught instanceof Error && caught.name === "ResourceNotFound") {
console.warn(
`${caught.message}. The asset model could not be found. Please check the asset model id.`,
);
} else {
throw caught;
}
}
};
// snippet-end:[iotsitewise.JavaScript.Basics.createAsset]
import { fileURLToPath } from "node:url";
// Call function if run directly
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const options = {
assetName: {
type: "string",
},
assetModelId: {
type: "string",
},
};
const { values } = parseArgs({ options });
main(values);
}