-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathhello.js
42 lines (36 loc) · 1.19 KB
/
hello.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { fileURLToPath } from "node:url";
// snippet-start:[javascript.v3.support.scenarios.Hello]
import {
DescribeServicesCommand,
SupportClient,
} from "@aws-sdk/client-support";
// Change the value of 'region' to your preferred AWS Region.
const client = new SupportClient({ region: "us-east-1" });
const getServiceCount = async () => {
try {
const { services } = await client.send(new DescribeServicesCommand({}));
return services.length;
} catch (err) {
if (err.name === "SubscriptionRequiredException") {
throw new Error(
"You must be subscribed to the AWS Support plan to use this feature.",
);
}
throw err;
}
};
export const main = async () => {
try {
const count = await getServiceCount();
console.log(`Hello, AWS Support! There are ${count} services available.`);
} catch (err) {
console.error("Failed to get service count: ", err.message);
}
};
// snippet-end:[javascript.v3.support.scenarios.Hello]
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
main();
}