-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathshared.js
More file actions
33 lines (30 loc) · 851 Bytes
/
shared.js
File metadata and controls
33 lines (30 loc) · 851 Bytes
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
ElasticLoadBalancingV2Client,
paginateDescribeLoadBalancers,
} from "@aws-sdk/client-elastic-load-balancing-v2";
export async function findLoadBalancer(loadBalancerName) {
const client = new ElasticLoadBalancingV2Client({});
const paginatedLoadBalancers = paginateDescribeLoadBalancers(
{ client },
{
Names: [loadBalancerName],
},
);
try {
for await (const page of paginatedLoadBalancers) {
const loadBalancer = page.LoadBalancers.find(
(l) => l.LoadBalancerName === loadBalancerName,
);
if (loadBalancer) {
return loadBalancer;
}
}
} catch (e) {
if (e.name === "LoadBalancerNotFoundException") {
return undefined;
}
throw e;
}
}