-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathlist-account-aliases.js
More file actions
44 lines (36 loc) · 1.29 KB
/
list-account-aliases.js
File metadata and controls
44 lines (36 loc) · 1.29 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { fileURLToPath } from "node:url";
// snippet-start:[iam.JavaScript.alias.listAccountAliasesV3]
import { ListAccountAliasesCommand, IAMClient } from "@aws-sdk/client-iam";
const client = new IAMClient({});
/**
* A generator function that handles paginated results.
* The AWS SDK for JavaScript (v3) provides {@link https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html#paginators | paginator} functions to simplify this.
*/
export async function* listAccountAliases() {
const command = new ListAccountAliasesCommand({ MaxItems: 5 });
let response = await client.send(command);
while (response.AccountAliases?.length) {
for (const alias of response.AccountAliases) {
yield alias;
}
if (response.IsTruncated) {
response = await client.send(
new ListAccountAliasesCommand({
Marker: response.Marker,
MaxItems: 5,
}),
);
} else {
break;
}
}
}
// snippet-end:[iam.JavaScript.alias.listAccountAliasesV3]
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
for await (const alias of listAccountAliases()) {
console.log(alias);
}
}