-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathlist-command-invocations.js
47 lines (45 loc) · 1.52 KB
/
list-command-invocations.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
42
43
44
45
46
47
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[ssm.JavaScript.Basics.listCommandInvocations]
import { paginateListCommandInvocations, SSMClient } from "@aws-sdk/client-ssm";
import { parseArgs } from "node:util";
/**
* List SSM command invocations on an instance.
* @param {{ instanceId: string }}
*/
export const main = async ({ instanceId }) => {
const client = new SSMClient({});
try {
const listCommandInvocationsPaginated = [];
// The paginate function is a wrapper around the base command.
const paginator = paginateListCommandInvocations(
{ client },
{
InstanceId: instanceId,
},
);
for await (const page of paginator) {
listCommandInvocationsPaginated.push(...page.CommandInvocations);
}
console.log("Here is the list of command invocations:");
console.log(listCommandInvocationsPaginated);
return { CommandInvocations: listCommandInvocationsPaginated };
} catch (caught) {
if (caught instanceof Error && caught.name === "ValidationError") {
console.warn(`${caught.message}. Did you provide a valid instance ID?`);
}
throw caught;
}
};
// snippet-end:[ssm.JavaScript.Basics.listCommandInvocations]
import { fileURLToPath } from "node:url";
// Call function if run directly
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const options = {
instanceId: {
type: "string",
},
};
const { values } = parseArgs({ options });
main(values);
}