-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathsend-command.js
41 lines (39 loc) · 1.15 KB
/
send-command.js
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[ssm.JavaScript.Basics.sendCommand]
import { SendCommandCommand, SSMClient } from "@aws-sdk/client-ssm";
import { parseArgs } from "node:util";
/**
* Send an SSM command to a managed node.
* @param {{ documentName: string }}
*/
export const main = async ({ documentName }) => {
const client = new SSMClient({});
try {
await client.send(
new SendCommandCommand({
DocumentName: documentName,
}),
);
console.log("Command sent successfully.");
return { Success: true };
} catch (caught) {
if (caught instanceof Error && caught.name === "ValidationError") {
console.warn(`${caught.message}. Did you provide a valid document name?`);
} else {
throw caught;
}
}
};
// snippet-end:[ssm.JavaScript.Basics.sendCommand]
import { fileURLToPath } from "node:url";
// Call function if run directly
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const options = {
documentName: {
type: "string",
},
};
const { values } = parseArgs({ options });
main(values);
}