forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-asset.js
More file actions
47 lines (44 loc) · 1.2 KB
/
delete-asset.js
File metadata and controls
47 lines (44 loc) · 1.2 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[iotsitewise.JavaScript.Basics.deleteAsset]
import {
DeleteAssetCommand,
IoTSiteWiseClient,
} from "@aws-sdk/client-iotsitewise";
import { parseArgs } from "node:util";
/**
* Delete an asset.
* @param {{ assetId : string }}
*/
export const main = async ({ assetId }) => {
const client = new IoTSiteWiseClient({});
try {
await client.send(
new DeleteAssetCommand({
assetId: assetId, // The model id to delete.
}),
);
console.log("Asset deleted successfully.");
return { assetDeleted: true };
} catch (caught) {
if (caught instanceof Error && caught.name === "ResourceNotFound") {
console.warn(
`${caught.message}. There was a problem deleting the asset.`,
);
} else {
throw caught;
}
}
};
// snippet-end:[iotsitewise.JavaScript.Basics.deleteAsset]
import { fileURLToPath } from "node:url";
// Call function if run directly
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const options = {
assetId: {
type: "string",
},
};
const { values } = parseArgs({ options });
main(values);
}